-
cocl Newbie

-
Posts: 3
Threads: 0
Joined: Jun 2020
Reputation:
0
06-14-2020, 10:33 PM
(This post was last modified: 06-15-2020, 12:13 PM by jreklund.)
PHP Code: <?php namespace App\Controllers;
use TCPDF;
class Home extends BaseController { public function index() { $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->Output('example.pdf', 'I'); } }
Code: <Output>
%PDF-1.7 %���� 7 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20200615132610+08'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /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��RMo�0��W�#�&i҅�Ƈĉm9L.#P � դ��S�m��C;Y�l?�Op�,H 0%�b��ϓNHs�␌%��� F�����*��!n�ې�)7�2W{�|:�a�����N-VJ�����@^�mj.(U�cޛa]�=�Np����^��~Ë2_��K�il�a�G�ך��u�o8ޏ�>�_�j��#�8�,O�u�&��@eW�>�vf�{�2�����Tmlt=I�:�q��DY3��})3�� endstream endobj 1 0 obj << /Type /Pages /Kids [ 7 0 R ] /Count 1 >> 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 595.276000 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 162 >> stream x���1�0����u��I����nj��-X�ҿ�K!hQ5p$�����A��x�6 %m5_'(��3����jX�u&54}Kޠ �zp0��o���j��cT�oƙbB�ºGl�Ԟ��}�_�ҧ�C�g�~��'�Kc�#WX�d �p/8��|4�[� 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.3.5 \(http://www.tcpdf.org\)) /CreationDate (D:20200615132610+08'00') /ModDate (D:20200615132610+08'00') /Trapped /False >> endobj 10 0 obj << /Type /Metadata /Subtype /XML /Length 4640 >> stream application/pdf 2020-06-15T13:26:10+08:00 2020-06-15T13:26:10+08:00 2020-06-15T13:26:10+08:00 TCPDF 6.3.5 (http://www.tcpdf.org) uuid:be5c4176-78b3-9981-4463-f172485ef20f uuid:be5c4176-78b3-9981-4463-f172485ef20f http://ns.adobe.com/pdf/1.3/ pdf Adobe PDF Schema internal Adobe PDF Schema InstanceID URI 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 http://www.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 0000000807 00000 n 0000001523 00000 n 0000000866 00000 n 0000001083 00000 n 0000000972 00000 n 0000001648 00000 n 0000000015 00000 n 0000000483 00000 n 0000001864 00000 n 0000002061 00000 n 0000006784 00000 n trailer << /Size 12 /Root 11 0 R /Info 9 0 R /ID [ ] >> startxref 6993 %%EOF
-
badger Member
  
-
Posts: 84
Threads: 22
Joined: Apr 2015
Reputation:
2
(06-15-2020, 12:17 PM)jreklund Wrote: That's not a CodeIgniter problem, as it loading the library. That's a TCPDF problem and I'm guessing it's do to the fact you aren't sending any application/pdf headers from your server. By coincidence, I've just spent the last 2 hrs fighting hard with the same problem and I don't believe it has anything to do with tcpdf because I have tried it with a regular pdf from elsewhere. Using force_download in ci3 has worked perfectly for the past 2/3 years. I've tried every combination of the following code and nothing works. If I enable the line " Code: setContentType('application/pdf')
" then Chrome reports "unable to download" but firefox reports "might not be displayed correctly" and using "open with different viewer" dialog says the document has 0 bytes
Code: return $this->response//->setHeader('Pragma','public')
//->setHeader('Expires','0')
//->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
//->setHeader('Content-Disposition','inline; filename="'.$filename.'"')
//->setContentType('application/pdf')
//->setHeader('Content-Length',filesize($fullname))
->download($fullname);//'',true);//,$data);
I can create pdf files with tcpdf in ci4 and view them standalone with no problem but am unable to download via ci4.
Bill
07-05-2020, 02:12 AM
(This post was last modified: 07-05-2020, 04:41 AM by [email protected].)
*** SOLVED CI4 + TCPDF***
I had same problem. TCPDF was showing weird characters like %PDF-1.7 %���� 5 0 obj << /Type /Page /Parent 1 0 R
I just added exit(); at the end of the code. It works for me.
Example:
$pdf->Output('filename.pdf', 'I');
exit();
-
lomali Newbie

-
Posts: 7
Threads: 1
Joined: Apr 2020
Reputation:
0
(04-30-2020, 04:31 PM)jreklund Wrote: This should do the trick.
Code: composer require tecnickcom/tcpdf
PHP Code: <?php namespace App\Controllers;
use TCPDF;
class Home extends BaseController { public function index() { $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); } }
How I can run TCPDF without composer?
-
badger Member
  
-
Posts: 84
Threads: 22
Joined: Apr 2015
Reputation:
2
I installed it as an unzip into thirdparty/TCPDFMaster and created a file MyPdf.php in libraries with the following
PHP Code: <?php namespace App\Libraries; use App\ThirdParty\TCPDFmaster\Tcpdf; class MyPdf extends TCPDF { function __construct() { parent::__construct(); } }
and then in my controller
PHP Code: $pdf = new MyPdf(); $pdf->AddPage(); $pdf->writeHTMLCell(.... etc etc $filename=whatever; $file = fullpathto $filename; // save as file $pdf->Output($file, 'F'); // send to browser $this->response->setHeader('Content-Type', 'application/pdf'); $this->response->setHeader('Content-Disposition: inline;', 'filename="' . $filename . '"'); $this->response->setHeader('Content-Transfer-Encoding', 'binary'); $this->response->setHeader('Content-Length: '. filesize($file),''); $this->response->setHeader('Accept-Ranges:', 'bytes'); readfile($file);
-
lomali Newbie

-
Posts: 7
Threads: 1
Joined: Apr 2020
Reputation:
0
|