1

I am creating a module to generate dynamic product PDFs with FPDF My problem is I cant get the pdf to render / download as there is already html on the page.

I have created a layout template at Me/MyMod/view/frontent/layout/productpdf_index.xml

  <body>
    <referenceContainer name="content">
         <block class="Modzinc\Productpdf\Block\Product\View\Link"
               name="modzinc.dynamicpdf.linddsk"
               template="Modzinc_Productpdf::product/view/thepdf.phtml"
                after="-">
        </block>
     </referenceContainer>
 </body>

And I have a template file thepdf.phtml

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, 'Hello World!');
header('Content-type: application/pdf');
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: inline; filename='example2.pdf'");
$pdf->Output('example2.pdf', 'I');

Now the pdf libary works but I am getting a page rendered as so

%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 <> stream 
x�]R�n�0��>��L�%�DI�8���~�%E*r�ﻻvҪHX�gvVk? /
���Ῑ��`]�[�x5 �3\z��P�}
����PO���j�Jݍ^���x6/f�����������|���4}�z�����}
���@�,ۖ-��˺E�u�^�,���<� �Z_�K� IQ����Yd����C�K�_�%q�8>�!J"V!2&bGģ%r"H��D��\}2EL1n��h�j���e��"a*H����:��d��9c���[�X1~��"�3�g��Ñ�;O��> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R >> /XObject << >> >> endobj 7 0 obj << /Producer (FPDF 1.81) /CreationDate (D:20170512141922) >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 9 0000000000 65535 f 0000000228 00000 n 0000000867 00000 n 0000000009 00000 n 0000000087 00000 n 0000000315 00000 n 0000000749 00000 n 0000000971 00000 n 0000001047 00000 n trailer << /Size 9 /Root 8 0 R /Info 7 0 R >> startxref 1096 %%EOF

Now I know why this is its because my page mysiet.com/productpdf is rendering all the usual magento head html and body class stuff so the pdf wont work as the header has already been declared.

I need to know how what I need to put in my page layout file ( productpdf_index_index.xml ) To tell magento just load the thepdf.phtml template file with NO ! other markup, like a completely blank page.

Can anyone help me I suppose I just need a new Blank page layout but I cant figure out how to do it

thanks in advcance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.