0

I am trying to use mPDF to convert a site into PDF.

The thing is that my site is a PHP variable page, which displays information for customers depending on their username and order ID. However, the website name is always the same: personalArea.php.

So, I would like to have a link that says Export to PDF, so the user exports his information.

I am planning on using file_put_contents to put the current page into a HTML file and then use the mPDF to export that HTML into PDF. Is this a good practice? My concern is the volume, I would be creating many HTMLs... I could delete them immediately, but not sure if there is a better way to do this.

Thanks

1 Answer 1

1

I've used mPDF before and a simple sample code could be:

$yourHtml = "ABCD.html";
$mpdf=new mPDF();
$stylesheet = file_get_contents('design.css'); //if you wanted some styling
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML(file_get_contents($yourHtml)); 
unlink($yourHtml); //You could delet your file after showing it if it is just on the fly
$mpdf->Output();
exit;
Sign up to request clarification or add additional context in comments.

Comments

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.