Web Page To PDF Converter in PHP

Web Page To PDF is a simple feature, You can download any web page as PDF format and save to your local drive using Web Page To PDF Converter. This is an important tool for a website to increase impression and user experience. Today I am going to discuss convert web page to pdf using PHP. It's a good service so that webmasters eager to convert web page to pdf using php and randomly searching for web page to pdf php script. It's pretty easy to Creating PDF in PHP. We use mpdf library  to make this. Follow the step by step instruction to install this.

Download mPDF Library

At first, download the mPDF library and extract it. Then create a file to execute PDF. I am going to create an index.php file to make an example. Create this file and write down this code.

$site = 'http://example.com';
$title = 'myPDF'; // Your own title
include("mpdf.php"); //include mpdf.php file from mPDF library
$mpdf=new mPDF('win-1252','A4','','',15,10,16,10,10,10);//A4 page in portrait for landscape add -L.
$mpdf->useOnlyCoreFonts = true;
$file = file_get_contents($site);
echo $file; //this is webpage content
$html = ob_get_contents();
//$mpdf->SetProtection(array(), 'user', 'password'); uncomment to protect your pdf page with password. // If you want to use password.
The Web To PDF maker is ready. If you execute this script this script will create a PDF of example.com and download it. If you want only show PDF in browser than leave $mpdf->Output(); value empty.

I hope you understand how to convert a web page to PDF in PHP. If you have any question or comment about this Web Page To PDF Converter in PHP article please don't hesitate to do that, please comment your question in comment section.

Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Need Assistance?

I'm Sajjad Hossain, working on web application development since 2012. Do you need assistance on your project? or are you stuck with problems? I am available to help you.
If you want to contact with me ping me at -


We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy