Is it not possible to generate a PDF using TCPDF while placing the HTML within the template view?
Example:
details.html.pdf:
<?php
$html = ' //all the stuff i want to appear on the pdf ';
$filename = $emailReport['subject']; //Outputs 'Email Report From Database' in output
$pdf->writeHTMLCell($w = 250, $h = 200, $x = '', $y = '', $html, $border = 0, '', $fill = 0, $reseth = true, $align = 'center', $autopadding = true);
$pdf->Output($filename,'I');
}
DefaultController.php
public function printAction()
{
return $this->delegateView(
[
'viewParameters' => [
'pdf' => $pdf
],
'contentTemplate' => 'PrintoutBundle:Default:pdf.html.php',
'passthroughVars' => [
'activeLink' => '#printout_email',
'mauticContent' => 'email',
'route' => $this->generateUrl('printout_email'),
],
]
);
}
Gives me:
%PDF-1.7 %���� 7 0 obj << /Type /Page /Parent 1 0 R /LastModified (D:20161121165447-06'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 >> /PZ 1 >> endobj 8 0 obj <> stream x���S�6���W��ݴ7 ,ɒ�}�]������\g��t�D$n+�\��ܿ{rb��HlCl�0!�l��<�G�,�v ��7����?����}��o���;����/���N�����o��dk�]�S(���~vN��+Sf�3?�:�G�?�c�b��/�������s�C ����w(�x~p�o��Y�l=��PBU��Q���r0@�֪��w�+|�?A�nfW // more of this for dozens more lines ��������j�W�\�6m�֭[/^LwY���:fp��A��\�vmpp�v16�� ��Q0�Bl5��T���A&�=`F�XX^!c�LK(� �_��WCCC���� � �Q���LK���W� endstream endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 3 0 R /F2 4 0 R /F3 5 0 R >> /XObject << /I0 13 0 R /I1 14 0 R /I2 15 0 R /I3 16 0 R >> >> endobj 6 0 obj <> /H /I>> endobj 17 0 obj << /Title (��Report Generated Nov 21, 2016) /Subject (��Email Subject from Database) /Producer (��TCPDF 6.2.12 (tcpdf.org)) /CreationDate (D:20161121165447-06'00') /ModDate (D:20161121165447-06'00') /Trapped /False >> endobj 18 0 obj << /Type /Metadata /Subtype /XML /Length 4307 >> stream application/pdf Generated Nov 21, 2016 Email Subject from the Database 2016-11-21T16:54:47-06:00 2016-11-21T16:54:47-06:00 2016-11-21T16:54:47-06:00 TCPDF 6.2.12 (tcpdf.org) uuid:4945196b-d05c-76e8-8a79-e9009fcad893 uuid:4945196b-d05c-76e8-8a79-e9009fcad893 ns.adobe.com/pdf/1.3/ pdf Adobe PDF Schema ns.adobe.com/xap/1.0/mm/ xmpMM XMP Media Management Schema internal UUID based identifier for specific incarnation of a document InstanceID URI 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 19 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 18 0 R >> endobj xref 0 20 0000000000 65535 f 0000006237 00000 n 0000035774 00000 n 0000006309 00000 n 0000006415 00000 n 0000006526 00000 n 0000035942 00000 n 0000000015 00000 n 0000000465 00000 n 0000003474 00000 n 0000003925 00000 n 0000004460 00000 n 0000004930 00000 n 0000006640 00000 n 0000006938 00000 n 0000014933 00000 n 0000023217 00000 n 0000036214 00000 n 0000036602 00000 n 0000040992 00000 n trailer << /Size 20 /Root 19 0 R /Info 17 0 R /ID [ <4945196bd05c76e88a79e9009fcad893> <4945196bd05c76e88a79e9009fcad893> ] >> startxref 41201 %%EOF
However, if I place all of my code within the controller and completely skip using the template file, it loads perfectly.
$this->delegateView() sends data from my controller to the template. (I've also tried making this $html = $this->delegateView(..) to no avail.)
Editing the controller like so:
return $pdf->writeHTMLCell($this->delegateView(
[ 'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('attachment; filename="%s"', $filename), //$pdf->Output($filename,'I'),
'viewParameters' => [
'pdf' => $pdf,
'objectId' => $objectId
//more stuff sent to the template
]
]
));
in attempts to generate the PDF (while the content has been moved from the controller to the template), the PDF does not create. I think I am wrapping the TCPDF service incorrectly, but I cannot figure out how to do it appropriately.
details.html.php
. 2 -- TheOutput
command takes as first argument a pdf extension. Is$filename
a PDF? – ZugZwangwriteHTMLCell
method. Focus on the first example. Have you tried to launchob_clean()
before the Output command? – ZugZwang