Am using Codeigniter 4 and trying to convert a dynamic HTML (invoice) to pdf so it can be download when a user click on a button. It was working perfectly on my local machine chrome and edge browser, but when I tried to test it on my phone chrome it will add .html at the end of the file extension and when I opened it I see a bunch of codes, but when I tried with opera mini on phone is working well.
Here is the code I have tried and the image of random error am having.
public function getInvoice($id){
$options = new Options();
$options->set('isRemoteEnabled', true);
$options->set('enable_css_float', false);
$dompdf = new Dompdf($options);
$getTransaction = $this->BasicModel->getTransaction($id);
$dompdf->setPaper('A4', 'potrait');
$dompdf->loadHtml(view('backend/templates/invoice', compact('getTransaction'))); //Loading my view here
$dompdf->render();
ob_clean();
$dompdf->stream('sebededata-invoice-'.$getTransaction->trans_ref . '.pdf');
}
Here is the error am having when I opened the file downloaded on Mobile chrome
%PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R /F3 11 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (þÿdompdf 1.0.2 + CPDF) /CreationDate (D:20210901212045+01'00') /ModDate (D:20210901212045+01'00') /Title (þÿExample 1) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Annots [ 13 0 R ] /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 1046 >> stream xœ VMoÜ6½ï¯˜cØ,¿IùÔ$u¨ƒÖ‹^’ä]ÚV½’\Ik#ÿ> »+‰öʉPØ&çqæÍg‚qÎ)]›Û…VŒKJï6#8“Ê’sŠy“Qèfñß"7†øN‰÷ H«™òšœ’Ì;M«rq€NÏž¦"hÄ '=§ øûw<ÿâLï4Æõï?‚™ä <Øa#Ë™Øo&ºW‹¿v(v§?®G(šIà ^(EåÂdÌá[üÞ̇ÁÍÜJR;õ¨ÜªhN4q öæ¥+"ð~9Ò˜)&#ãrM¿ü®È3NË¢Ïo.Êü6PUwtSo«5Õ ußm«ûª~ªÞ~¥åG:_âžíˆv1ZÒù$Äà™rCŒ•`Zù}ˆ9S6jh!ã# ;!„Û0' S°´$c(”ƒd“H4³2J¥^€+_X5õ’M" žw#Ð(ÐdZGR¡í4nåˆYOª ‰ŒéY½üçÓŇó”½}š"vH(ãHÙm¸'ë#‰W=R6„ç*\‡uXç]Nê²ÜVÅ*ïŠzŒK ‚ä²Üƒ\ÖäèÓ¦n¶U[ßÖtÕ5!t'ô>o‹¦8¡I0í™ÏÄ1Ø»u}z~_tÐÛm#Ë»0 ¡<Yvñå åòË[òBëL+ø !»œU6“Ò$¬MäNz tØÝñ«ºêòU÷k;°ÇVu™àê¾Â>}Å?ëňi˜q2f rŠK>H6tM‡Øqæq«1q£ðnÿêyËt“YIɤÌÉm¢¦àŸÅ…QÙ¢f¥?voÙäUÿ (²›Ð„jÎ÷2+(];ܯ ¬—$Q¤\*Ò Y¸¾V yi÷XM/<™Ìo%ñìEm+Y¦ù±+È üu&v'L$s˜„ŠÆÃt\^ÈÝm{öÓ:üˆwë‰ \mW«Ð¶7ÛÍ,g¸aBðÔ™ƒd†3Ú¼>zêh‹U %Þï™Ù Ñ´ði6 ûlø1Ñc&H}W4]Q†9Dô÷ Dô’9Dè8*È J´²n~T5Üöv‚ÑK!³³‘h Ò¦Ž$sáñ¥›¨Ž?ëëbèr[^‡ffHÑFWúÿ…†7Á( Oµ°Â˜YÅÚÛ0²ÑKúGô5E-þRŃd *ö?;Qœ¿¡AÍφ£ýD4$—â”»SiHˆ3ü*9k<’YûÄ0¡kyÅ÷yuÄÀØ,qHqèºC‹“ß7 »¼ºo1µ5ôÞ6ô wM]a˜cÏ"ô¼[¥3“Ö>Žv‚d6ò;VÇѨÿ~mªƒÙ`!#oÀ e'òè¢z¬ãõ”·´j₉³¢œÐž¶]h(ÇZ´ô˜oŠ5=Ý]½í¨»Ô·k° ´!ߎ~»Á3 endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Times-Bold /Encoding /WinAnsiEncoding >> endobj 10 0 obj [6 0 R /Fit] endobj 11 0 obj << /Type /Font /Subtype /Type1 /Name /F3 /BaseFont /Times-Roman /Encoding /WinAnsiEncoding >> endobj 12 0 obj [6 0 R /Fit] endobj 13 0 obj << /Type /Annot /Subtype /Link /A 14 0 R /Border [0 0 0] /H /I /Rect [ 432.5080 626.6971 524.0200 635.6071 ] >> endobj 14 0 obj << /Type /Action /S /URI /URI (mailto:contact#sebededata.com) >> endobj 15 0 obj [6 0 R /Fit] endobj xref 0 16 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000295 00000 n 0000000324 00000 n 0000000503 00000 n 0000000625 00000 n 0000001744 00000 n 0000001853 00000 n 0000001961 00000 n 0000001990 00000 n 0000002100 00000 n 0000002129 00000 n 0000002257 00000 n 0000002338 00000 n trailer << /Size 16 /Root 1 0 R /Info 5 0 R /ID[<7abfe18a36062956fc713cf29e74e28c><7abfe18a36062956fc713cf29e74e28c>] >> startxref 2367 %%EOF
I was able to solve this by adding exit(); after $dompdf->stream('sebededata-invoice-'.$getTransaction->trans_ref . '.pdf');
Related
I am using some APIs that allow a PDF report upload directly on my server.
I'm executing a request, and the remote system reply with a POST request with the PDF file.
Here is my problem:
$request->all() //empty
Prints:
array(
)
Instead:
$request->getContents()
Prints:
--ajAJnndaskkASIdjasdasmdadas
Content-Disposition: form-data; name="file"; filename="k7qtpl02srmhe3fnjuzc4wbgd8oa1yv695xi.pdf"
%PDF-1.3
1 0 obj
<<
/Type /Pages
/Count 3
/Kids [ 3 0 R 4 0 R 5 0 R ]
>>
endobj
2 0 obj
<<
/Producer (PyPDF2)
/process_id (k7qtpl02srmhe3fnjuzc4wbgd8oa1yv695xi)
>>
endobj
3 0 obj
<<
/Type /Page
/Resources <<
/ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ]
/ExtGState <<
/G3 7 0 R
/G5 8 0 R
>>
/XObject <<
/X7 9 0 R
/X9 10 0 R
/X10 11 0 R
/X11 12 0 R
>>
/Font <<
/F4 14 0 R
/F6 19 0 R
/F8 24 0 R
>>
>>
/MediaBox [ 0 0 612 792 ]
...and so on. All this strings finish with:
-----ajAJnndaskkASIdjasdasmdadas------
I need to store this pdf using laravel Storage.
How can i get the $file object?
APIs documentation does not specify any kind of information about the request.
I have a stranger document that I don't know which extension it is, and I need to convert it into a PDF, so the idea is to get that content dynamically, then we save it in server as a PDF
My try :
$responce = $this->getDocumentContent();//this function returns me the $responce content bellow.
$documentFolder = $this->getDirectory().'/document/'; //var/www/project/document/
$documentFullPath = $this->getDirectory().'/document/file1.pdf';
$this->_io->mkdir($documentFolder, 0775);//create folder var/www/project/document
$document = fopen($documentFullPath, "w+");//create pdf file var/www/project/document/file1.pdf
fwrite($document, $responce);
fclose($document);
Now with this code, I create well the file1.pdf in var/www/project/document/file1.pdf but it is empty !, there is no content, the file1.pdf weight is not 0 but 163.2 Ko but I see anything. I don't know where is the issue.
$responce =
string(163146) "%PDF-1.4
%????
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/Metadata 63 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [ 01 0 R 8 0 R ]
/Count 2
/MediaBox [ 0 0 618 003 ]
>>
endobj
3 0 obj
<<
/ModDate (D:20190907120701+02'00')
/CreationDate (D:20130904150701+02'00')
/Title (F:/Data/Composer/0510.IN.PDF)
/Subject (NONE)
/Author (User: Windows XP/ User)
/Creator (PDF/PReS Version: 6.1.1 )
/Producer ([ClibPDF Library 2.02-r1-2] Windows XP)
>>
endobj
5 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources << /Font << /Fcpdf0 30 0 R >> /XObject << /6p 8 0 R >> /ProcSet 7 0 R >>
/MediaBox [ 0 0 595 842 ]
/CropBox [ 0 0 595 842 ]
/Rotate 0
/Contents 6 0 R
>>
endobj
6 0 obj
<< /Length 246 /Filter [ /FlateDecode ] >>
stream
x??QMk?#?'1?bia=?!?L6I7?V??AB??AQ(???_:?T?"$;<vf??7?I??c?(?(?????F??4?E?<L?ku????xs???w*??
??FGD?AlY?{,???E??-A????u?o?/^^O%|??>???\?T?Y
??iS??5q?t?C2I??q???c>?V?z?8:??C??#???p/?\???0F)k#?1???U?`Sa?????.???PyoY
endstream
endobj
7 0 obj
[
/PDF /Text /ImageC
]
endobj
8 0 obj
<< /Type /XObject /BBox [ 0 0 595 842 ] /Filter /FlateDecode /FormType 1
/Length 17871 /Matrix [ 1 0 0 1 0 0 ] /Resources << /ColorSpace << /CS0 27 0 R /CS1 26 0 R /CS10 27 0 R /CS11 26 0 R /CS12 27 0 R /CS13 26 0 R
/CS14 29 0 R /CS15 28 0 R /CS16 29 0 R /CS17 28 0 R /CS18 29 0 R
/CS19 28 0 R /CS2 27 0 R /CS20 29 0 R /CS21 28 0 R /CS22 29 0 R
/CS23 28 0 R /CS24 29 0 R /CS25 28 0 R /CS26 29 0 R /CS27 28 0 R
/CS28 29 0 R /CS29 28 0 R /CS3 26 0 R /CS30 29 0 R /CS31 28 0 R
/CS32 29 0 R /CS33 28 0 R /CS34 29 0 R /CS35 28 0 R /CS36 29 0 R
/CS37 28 0 R /CS4 27 0 R /CS5 26 0 R /CS6 27 0 R /CS7 26 0 R /CS8 27 0 R
/CS9 26 0 R >>
/ExtGState << /GS6 25 0 R >> /Font << /TT24 21 0 R /TT25 17 0 R /TT26 13 0 R /TT27 9 0 R >>
/ProcSet [ /PDF /Text ] >>
/Subtype /Form >>
stream
x??}i?$????K?l2?#?:gu?F??????r$?im?1k???????E???????;?O???=????????????7?????o????oO??????}???O??uz?????z?O????p=M???4n~??w/??;|????OGw>???>???9???cSn'????b????5????????w??\????????_~????t?w8N??9??~?f}??qxy??????o???????M??????'?Or4|?O????|??y??o???=?=
?y?p??1vx?)??7???on????.??w?????-??K??|y:?w}d??????:???>uv??:?.???y???6?nm{????E0\??????n?????B??ra*??x?t?K^???'??7?i?8???]?p?D}??T??-?lcN???_????Q7h??n??s???n==?
??!?
?#~s??F8??G?0?K??e??ul?3n???g??????6?0?a???$??L?j?W??9~U??{?G?U??9fO?????rL?K[Z??E?!????}T|?yr/?}?+?O???6??um????a??E^?K??P??U:??+?pL??N?Q????^\?{a???[??k?N?t/????K{?Ek_???
???t??U#??\O;??????????5??~???????
K??O??9?????</?(?*7????u?n?xa?4??rbd??^N?^z??]?7?T????r?f????|Y?ij?mC'u3???o?4On?r???Kd+
?.??t?6??(?fa+5?$??5?}??,??ZB?Fe??E5W(??.J7??yk1??u?F\?o:^???hK???vNH?]?K???r?????U??H?d?????
X???[e3 7???????qz?K?7c1>?
??o?y??Q????<?8???G4??????^?u?&??&?r???'?o??LN?_?? l??1an+G9&?m?1~?'?e?<?
!??o?-??????J?r???x??`?/o?-??=????y?,????R?0y?? ??.rz|3?GhmS? U?!t????A?Oi????}?6??ct5?i???|?.?&?\??]???2?n?\?<7? ?>?4??"X1M?j??>H??}???iX??~???^?????q?????)
??;2?????'??bS????d???N?/L???K?\n?=n~&F?????fd;m?4?c????Xf??'9?D?s????`4,Mg?f????F??n?~-?????+#l??1??z?N�????l??$??+J?N6? ???}:j8Q?????$L?|C?&???^ch?70??C(?????&??????8B?L.??A??D0]?5?+?)??d?X?>??0C??|?A?&?Z???H??J?0?(m?Rr?Y???*???3?o???{??c?[???E?5 ????q?k??:V;T4?+T??>*B(???|I??}?T??7?N??�?g?W?'??U?'2v`? 4????O?)??x?*r?,?b^7??/3??y(M?Nnnd??i??????:?,?|??EYtx/]?g?!?sgi-{?i<?"????????`??4?[�??h?s*???L?,#??8???G?-(%???=?o/A?????!?????_"??%????_??y???a?%???G4?r?|?M??#z=?~???&v?J?]?<?tQ?
??n?�j?GHh[???&J??!?p?l?b?_w?\ ?#?dXb??a}?l??????S5"D~?5??w??n?.v?C?^?E??;?]????#????a???Z>Tb?;Et U?<?; pl?k???b+?m??`????Is?$3<??6??K?w??
rz???e??i#?5$;-??q4Z"????(_5??E??L?ayv
y?s?M?????R?p?T8?-B?o??i?_?~\??????t??]7a?? K~9!?
?_y.H??8??5z?%?B?w?Vy?}`!h1??? ?v?u?i????????r?&?t?"??%Om??:???a3Y??j?P7?N???(?zu???6I$Z/?"??v^??? mp??/?
h?I?'?V?9'Iexj}?z?t?S?*Y?m3i?J?H??Q???3???dUd?fk???}m????k???!H?%I>??????"???[\|*V??~J??????i-??Z??H??ayb????Ca?i^cP??i???r????????L??4??#??RH???(?Jb??[f??N?1;???&.
???Q???~~???e;?&[? ???0>wRI???s??c%"r???x??n?r}?b??j?h?MO???? q??'?#v$?????g?Xd?h?Pl:?M?\???9B5�?G?j??IE?J?~??????M ??A?<?[???/P7n??Q??0ej?_c?J?u??+J?xl???f?)?0? K?*??W519??uy??r6}?? ?N???s?)?X???????2-?j??b\????M{?f?????E?|?-???x+?zN?f�3?)^k'?qR????zevW?,d?V??????{6!?? ??#j?y?,?BZQ????!?eW???M??
U???D
Q)vWL?N?&??T?q_C?j??#?p??????V????It?.??[??-g<]i?.T�?6%|?W??n?3?x?xx??,???b&?e??Q]???Z?&l"?L???S??N ??F???+W??y??�%??Q-oc????d?S?6???/ ?_??&?t???8p??U??�Z?
?�+^???J???? r ?k??wIB?o?P?Z?]?X???c??6N??I&w?????i"I\??v2Jr?[?(??4?}?q???t?4??!?????B??<o???Q[??Q??A???mG???Q?<???f?P??
?????????Lp1??6F ?L;??J???????/????l?i??u?1??rw?
??c????????G??W??R?o?|?fz EA????JA?Z?
???0?b?EHP?p??7=?]g>d'?mk?3?5M|?E?8?_?T.?,???M?,dnP?L???hs=?;&???????(L?????4_??a?R^?LX??o?v+????7???????(?P??)b??A$?f??#?GF1S??????8b??RM.>?_?!Ab?`?Fs???+?#?HV??iM44?;u<C?????M]H?]?XQ1?f?JG????n1
?R???8?????m?<?}D???)?W3?�??k???T???SI???G??G ?hS*???bD%?=p?f2?SO?K?5??9?^8??$??v??5?7.4k%_???}?Li?h?MHqf?2q?Rj-???,'?k?o?Y_zk?W??
H?QTs>c???fx?g???D|?H?d???V?]96?3?V?1?(????u?e,?B?+ ECl7D???b?C74???l?Bt
The PDF mentions it actually:
/Producer ([ClibPDF Library 2.02-r1-2] Windows XP)
ClibPDF support for PHP was moved into PECL a long time ago (with PHP 5.1). The extension was not object oriented, so here is some additional wrapper around it.
Alternatives are Haru, PDFlib, or one of the available PHP based libraries.
I have a stream document I think and I need to convert it into a PDF.
The idea is to save that stream it in server as a PDF
My code :
$responce = $this->getDocumentContent();//this function returns me the $responce content bellow.
$documentFolder = $this->getDirectory().'/document/'; //var/www/project/document/
$documentFullPath = $this->getDirectory().'/document/file1.pdf';
$this->_io->mkdir($documentFolder, 0775);//create folder var/www/project/document
$document = fopen($documentFullPath, "w+");//create pdf file var/www/project/document/file1.pdf
fwrite($document, $responce);
fclose($document);
Now with this code, I create well the file1.pdf in var/www/project/document/file1.pdf but it is empty !, there is no content, the file1.pdf weight is not 0 but 163.2 Ko but I see anything. I don't know where is the issue.
$responce =
string(163146) "%PDF-1.4
%????
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/Metadata 63 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [ 01 0 R 8 0 R ]
/Count 2
/MediaBox [ 0 0 618 003 ]
>>
endobj
3 0 obj
<<
/ModDate (D:20190907120701+02'00')
/CreationDate (D:20130904150701+02'00')
/Title (F:/Data/Composer/0510.IN.PDF)
/Subject (NONE)
/Author (User: Windows XP/ User)
/Creator (PDF/PReS Version: 6.1.1 )
/Producer ([ClibPDF Library 2.02-r1-2] Windows XP)
>>
endobj
5 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources << /Font << /Fcpdf0 30 0 R >> /XObject << /6p 8 0 R >> /ProcSet 7 0 R >>
/MediaBox [ 0 0 595 842 ]
/CropBox [ 0 0 595 842 ]
/Rotate 0
/Contents 6 0 R
>>
endobj
6 0 obj
<< /Length 246 /Filter [ /FlateDecode ] >>
stream
x??QMk?#?'1?bia=?!?L6I7?V??AB??AQ(???_:?T?"$;<vf??7?I??c?(?(?????F??4?E?<L?ku????xs???w*??
??FGD?AlY?{,???E??-A????u?o?/^^O%|??>???\?T?Y
??iS??5q?t?C2I??q???c>?V?z?8:??C??#???p/?\???0F)k#?1???U?`Sa?????.???PyoY
endstream
endobj
7 0 obj
[
/PDF /Text /ImageC
]
endobj
8 0 obj
<< /Type /XObject /BBox [ 0 0 595 842 ] /Filter /FlateDecode /FormType 1
/Length 17871 /Matrix [ 1 0 0 1 0 0 ] /Resources << /ColorSpace << /CS0 27 0 R /CS1 26 0 R /CS10 27 0 R /CS11 26 0 R /CS12 27 0 R /CS13 26 0 R
/CS14 29 0 R /CS15 28 0 R /CS16 29 0 R /CS17 28 0 R /CS18 29 0 R
/CS19 28 0 R /CS2 27 0 R /CS20 29 0 R /CS21 28 0 R /CS22 29 0 R
/CS23 28 0 R /CS24 29 0 R /CS25 28 0 R /CS26 29 0 R /CS27 28 0 R
/CS28 29 0 R /CS29 28 0 R /CS3 26 0 R /CS30 29 0 R /CS31 28 0 R
/CS32 29 0 R /CS33 28 0 R /CS34 29 0 R /CS35 28 0 R /CS36 29 0 R
/CS37 28 0 R /CS4 27 0 R /CS5 26 0 R /CS6 27 0 R /CS7 26 0 R /CS8 27 0 R
/CS9 26 0 R >>
/ExtGState << /GS6 25 0 R >> /Font << /TT24 21 0 R /TT25 17 0 R /TT26 13 0 R /TT27 9 0 R >>
/ProcSet [ /PDF /Text ] >>
/Subtype /Form >>
stream
x??}i?$????K?l2?#?:gu?F??????r$?im?1k???????E???????;?O???=????????????7?????o????oO??????}???O??uz?????z?O????p=M???4n~??w/??;|????OGw>???>???9???cSn'????b????5????????w??\????????_~????t?w8N??9??~?f}??qxy??????o???????M??????'?Or4|?O????|??y??o???=?=
?y?p??1vx?)??7???on????.??w?????-??K??|y:?w}d??????:???>uv??:?.???y???6?nm{????E0\??????n?????B??ra*??x?t?K^???'??7?i?8???]?p?D}??T??-?lcN???_????Q7h??n??s???n==?
??!?
?#~s??F8??G?0?K??e??ul?3n???g??????6?0?a???$??L?j?W??9~U??{?G?U??9fO?????rL?K[Z??E?!????}T|?yr/?}?+?O???6??um????a??E^?K??P??U:??+?pL??N?Q????^\?{a???[??k?N?t/????K{?Ek_???
???t??U#??\O;??????????5??~???????
K??O??9?????</?(?*7????u?n?xa?4??rbd??^N?^z??]?7?T????r?f????|Y?ij?
...
I am using FPDF class in php to create pdf file in my webpage but it download the pdf but doesn't show it on the browser or create a garbage.
here is my code
<?php
require('fpdf/fpdf.php');
$pdf =new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output('file.pdf','D');
?>
this code download the pdf file but doesn't show the pdf file in the page
if i change the last line from
$pdf->Output('file.pdf','D'); to $pdf->Output('file.pdf','I');
it output this
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T04�30PISp �Z*�[����(hx����+����(j*�d��7W endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.7) /CreationDate (D:20150920120751) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 8 0000000000 65535 f 0000000228 00000 n 0000000416 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000520 00000 n 0000000595 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 644 %%EOF
any help
or can you recommend me other method to create pdf file in php
see http://www.fpdf.org/en/doc/output.htm
string Output([string dest [, string name [, boolean isUTF8]]])
so
$pdf->Output('I','file.pdf');
should do it.
I'm currently working on a PDF view for my cake application and found this tutorial.
http://www.startutorial.com/articles/view/how-to-create-pdf-helper-with-tcpdf
But currently I'm struggling over this error message:
Notice (8): Undefined variable: pdf [APP\View\Pdfs\index.ctp, line 2]
Notice (8): Trying to get property of non-object [APP\View\Pdfs\index.ctp, line 2]
Fatal error: Call to a member function addPage() on a non-object in \app\View\Pdfs\index.ctp on line 2
Can anyone help me out, what I have to adapt to CakePHP 2.0
For Cake 2.1, use this code:
<?php
$this->Pdf->core->addPage('', 'USLETTER');
$this->Pdf->core->setFont('helvetica', '', 12);
$this->Pdf->core->cell(30, 0, 'Hello World');
$this->Pdf->core->Output('example_001.pdf', 'D');
?>
When i use "$this->Pdf->core->Output('example_001.pdf', 'D');" pdf file is download fine. But when i use "$this->Pdf->core->Output('example_001.pdf', 'I');" to show in screen, i see:
%PDF-1.7 %���� 7 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20150318050138+01'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 612.000000 792.000000] /CropBox [0.000000 0.000000 612.000000 792.000000] /BleedBox [0.000000 0.000000 612.000000 792.000000] /TrimBox [0.000000 0.000000 612.000000 792.000000] /ArtBox [0.000000 0.000000 612.000000 792.000000] /Contents 8 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /Annots [ 6 0 R ] /PZ 1 >> endobj 8 0 obj <> stream x��SMo�0��W�#�棁� &Nl��I�e�T��2�I���ܢvCtZ�Ȋ��9/�f,� �$��zK�#�glb�%���2�=,]��t�uB\�G���#S����l��gO�:3��"*.~��Zr������^�UW���1�s�W�n��]�ϴ�J#�D���2��+�"ux����fsl!���t{��l3lH��'�-�����u�kO> endobj 3 0 obj <> endobj 5 0 obj <> endobj 4 0 obj << /Type /XObject /Subtype /Form /FormType 1 /Filter /FlateDecode /BBox [0.000000 0.000000 612.000000 28.350000] /Matrix [1 0 0 1 0 0] /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F2 5 0 R /F1 3 0 R >> >> /Length 161 >> stream x���?� �w?ō�bՇ���&���[�& �vh�|�>ҿ� �z�����#�T�B8`���Z�3:���[d��Q�:��|K^�2�z�Fp0�M7o���j���D��7*�{�ѯP]��r��o�sV�T�kqϛ���� �$�Ǒ3�#Y>�'��m�2�[� endstream endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 3 0 R /F2 5 0 R >> /XObject << /XT4 4 0 R >> >> endobj 6 0 obj <> /H /I>> endobj 9 0 obj << /Producer (��TCPDF 6.2.6 (tcpdf.org)) /CreationDate (D:20150318050138+01'00') /ModDate (D:20150318050138+01'00') /Trapped /False >> endobj 10 0 obj << /Type /Metadata /Subtype /XML /Length 4223 >> stream application/pdf 2015-03-18T05:01:38+01:00 2015-03-18T05:01:38+01:00 2015-03-18T05:01:38+01:00 TCPDF 6.2.6 (tcpdf.org) uuid:45f4b8fd-7424-3ef2-034a-a956c4a4d4ec uuid:45f4b8fd-7424-3ef2-034a-a956c4a4d4ec http://ns.adobe.com/pdf/1.3/ pdf Adobe PDF Schema http://ns.adobe.com/xap/1.0/mm/ xmpMM XMP Media Management Schema internal UUID based identifier for specific incarnation of a document InstanceID URI aiim.org/pdfa/ns/id/ pdfaid PDF/A ID Schema internal Part of PDF/A standard part Integer internal Amendment of PDF/A standard amd Text internal Conformance level of PDF/A standard conformance Text endstream endobj 11 0 obj << /Type /Catalog /Version /1.7 /Pages 1 0 R /Names << >> /ViewerPreferences << /Direction /L2R >> /PageLayout /SinglePage /PageMode /UseNone /OpenAction [7 0 R /FitH null] /Metadata 10 0 R >> endobj xref 0 12 0000000000 65535 f 0000000832 00000 n 0000001547 00000 n 0000000891 00000 n 0000001108 00000 n 0000000997 00000 n 0000001672 00000 n 0000000015 00000 n 0000000483 00000 n 0000001943 00000 n 0000002140 00000 n 0000006446 00000 n trailer << /Size 12 /Root 11 0 R /Info 9 0 R /ID [ <45f4b8fd74243ef2034aa956c4a4d4ec> <45f4b8fd74243ef2034aa956c4a4d4ec> ] >> startxref 6655 %%EOF