1

I am working with mPDF, I can't handle how to display php variable and generate&download PDF file. Example :

$a = '<head><body>Example</body></head>';
echo $a;
$mpdf = new mPDF();
$mpdf->WriteHTML('<head><body>Example</body></head>');
$mpdf->Output('filename.pdf', 'D');

This code only downloading pdf generated from ->WriteHTML but not displaying code above. I would display code and download pdf. Thx for tips.

1 Answer 1

0

You can't push a download and have it preceeded by HTML in one response.

You can work around this by outputting the HTML and have it include an IFRAME which has a src attribute of the url with the actual download.

dl_html.php:

<?php
$a = '<head><body>Example<iframe style="display:none;" src="dl_pdf.php"></iframe></body></head>';
echo $a;

dl_pdf.php:

 <?php
    include('mpdf.php');//or similar
    $mpdf = new mPDF();
    $mpdf->WriteHTML('<head><body>Example</body></head>');
    $mpdf->Output('filename.pdf', 'D');
Sign up to request clarification or add additional context in comments.

1 Comment

Can you write some simple example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.