32,000+ SUBSCRIBERS CAN'T GO WRONG !!!

phpans
GET TOP ARTICLES, SNIPPETS, SCRIPTS IN YOUR INBOX FOR FREE!

Delivered by GET EMAIL UPDATES FeedBurner
We always respect your privacy and take protecting it seriously.
We won't Spam You

Web Page To PDF Converter in PHP

, 0,
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.
<?php
$site = 'http://example.com';
$title = 'myPDF'; // Your own title
if(isset($title)){$title=$_POST['title'];}else{$title=null;}
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->SetHeader($title);
$mpdf->setFooter('{PAGENO}');
$mpdf->useOnlyCoreFonts = true;
$mpdf->SetDisplayMode('fullpage');
ob_start();
?>
<?php
$file = file_get_contents($site);
echo $file; //this is webpage content
?>
<?php
$html = ob_get_contents();
ob_end_clean();
$mpdf->WriteHTML($html);
//$mpdf->SetProtection(array(), 'user', 'password'); uncomment to protect your pdf page with password. // If you want to use password.
$mpdf->Output('myPDF.pdf','D');
exit;
?>

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.

Download PDF
Signup & Get $25 Free
Is this article helpful for you?





captcha

  • Connect
  •       
Top
Create an free account and start learning & sharing! Sign Up