Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the output of a php file into a variable using mPDF

Tags:

html

php

pdf

mpdf

I'm using mPDF library to provide pdf files.

Assume that I have a file named facture.php that contains :

  • an image in the header

  • a table in the body

  • an image in the footer of the file

And another file named convert_HTML2PDF.php that will provide the pdf output of the first file.

I would like to get the output of the facture file that is interpreted into a variable and output it as a pdf file without visualising in the browser.

How can I do that and use the output inside the convert_HTML2PDF.php?

like image 383
user2567806 Avatar asked Oct 23 '25 20:10

user2567806


2 Answers

$pdf = $mpdf->Output('', \Mpdf\Output\Destination::STRING_RETURN)

will output the PDF into a string - no need to create temp file.

like image 148
amik Avatar answered Oct 25 '25 11:10

amik


Use file_get_contents() to get html content of your facture.php :

$output = file_get_contents('http://www.example.com/facture.php');
like image 22
Charaf JRA Avatar answered Oct 25 '25 09:10

Charaf JRA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!