使用 TCPDF 为 CakePHP 2.0 创建 PDF 助手

问题描述 投票:0回答:3

我目前正在为我的蛋糕应用程序制作 PDF 视图,并找到了本教程。

http://www.startutorial.com/articles/view/how-to-create-pdf-helper-with-tcpdf

但目前我正在努力解决这个错误消息:

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

任何人都可以帮我吗,我必须适应 CakePHP 2.0

php cakephp-2.0 tcpdf
3个回答
2
投票

对于 Cake 2.1,请使用以下代码:

<?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');
?>

0
投票

用这个 $this->response->setHeader('Content-Type', 'application/pdf');


-1
投票

当我使用“$this->Pdf->core->Output('example_001.pdf', 'D');”时pdf文件下载正常。但是当我使用“$this->Pdf->core->Output('example_001.pdf', 'I');”时要在屏幕上显示,我看到:

%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 <> 流 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 >> >> /长度 161 >> 流 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 >> 流应用程序/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 架构 http://ns.adobe.com/xap/1.0/mm/ xmpMM XMP 媒体管理架构 基于内部 UUID 的文档特定化身标识符 InstanceID URI aim.org/pdfa/ns/id/ pdfaid PDF/ A ID Schema 内部 PDF/A 标准部分的一部分 整数内部 PDF/A 标准的修订 amd 文本内部 PDF/A 标准一致性的一致性级别 文本 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] /元数据 10 0 R >> endobj 外部引用 0 12 0000000000 65535 f 0000000832 00000 n 0000001547 00000 n 0000000891 00000 n 0000001108 00000 0000000997 00000 0000001672 00000 0000000015 00000 0000000483 00000 0000001943 00000 n 0000002140 00000 n 0000006446 00000 n 拖车 << /Size 12 /Root 11 0 R /Info 9 0 R /ID [ <45f4b8fd74243ef2034aa956c4a4d4ec> <45f4b8fd74243ef2034aa956c4a4d4ec> ] >> startxref 6655 %%EOF

© www.soinside.com 2019 - 2024. All rights reserved.