How to convert a PHP web page to PDF? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 11 years ago .

I have a PHP file that generates a report from the database, and I want this page to be converted into a PDF file, so it can be saved and printed. How do I convert a web page to a PDF? Is there any tool available or a PHP script?

8,665 17 17 gold badges 75 75 silver badges 120 120 bronze badges asked Aug 8, 2013 at 6:41 1,089 9 9 gold badges 22 22 silver badges 41 41 bronze badges Commented Aug 8, 2013 at 6:44 check this stackoverflow answer Commented Aug 8, 2013 at 6:45 possible duplicate of Webpage convert to PDF button Commented Aug 8, 2013 at 6:46 this link may help you web-to-pdf.com – user2543022 Commented Aug 8, 2013 at 6:56 use a save as PDF function like the one from HTM2PDF or something else Commented Aug 8, 2013 at 19:26

6 Answers 6

You can use MPDF, a PHP library which generates PDF files from UTF-8 encoded HTML. It's under GNU GPL v2 licence.

4,330 2 2 gold badges 31 31 silver badges 39 39 bronze badges answered Aug 8, 2013 at 7:10 Goutam Pal Goutam Pal 1,763 1 1 gold badge 10 10 silver badges 14 14 bronze badges

thanks for this, tried each of the answer given to me, and this is what I like the most, esp. converting HTML to PDF and its extensive documentation and this is I think the one I'll be using.

Commented Aug 10, 2013 at 1:03 Both links are dead. This is a good example why link only answer are BAD. Commented May 20, 2018 at 20:35 404 error page return Commented Jul 3, 2018 at 13:20 Someone must have seen your comments. Both links are active now. Commented Mar 12, 2019 at 17:41

Make use of TCPDF Plugin.

Here's an example and try this after configuring the above on your code.

SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); if (@file_exists(dirname(__FILE__).'/lang/eng.php')) < require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); > $pdf->SetFont('helvetica', '', 9); $pdf->AddPage(); $html = '

Example of HTML text flow

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B    ->    A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B ->    A + B = C    ->    C - B = A    ->    C - A = B

BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined BoldItalicUnderlined'; $pdf->writeHTML($html, true, 0, true, 0); $pdf->lastPage(); $pdf->Output('example_021.pdf', 'I'); ?>