Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a page as pdf in php

Tags:

php

Does anyone know how I can save a page as pdf in php?

Example: I have a page that is able to catch the users signature. Now I would like to create a button on the page that will convert the page into pdf so that the file can be saved to a folder.

Below you can see what the signature page looks like: enter image description here

like image 515
Jin Yong Avatar asked Sep 21 '11 06:09

Jin Yong


People also ask

How can I download HTML content as PDF in php?

We call the library and then continue to pass in the $html variable to the writeHTML() function. This prepares the PDF conversion. Next we use the output() function with the name of the PDF we want to generate and the second parameter of 'D' which instructs the output function to force the PDF file to download.

How create PDF in php explain with example?

php require('./fpdf. php'); $pdf=new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World! '); $pdf->Output(); ?> Upon execution, the PHP script will generate a PDF file in your browser.


2 Answers

There are a number of PHP PDF API and tools which convert or wrap up html content including drawings, links and images etc.

A very good thread from StackOverflow :

  1. Convert HTML to PDF using PHP
like image 88
KV Prajapati Avatar answered Oct 27 '22 23:10

KV Prajapati


TCPDF can output PDF's from html: http://www.tcpdf.org/

If you need to use more advanced html you can use WKHTMLTOPDF: http://wkhtmltopdf.org/

like image 28
Ali Gangji Avatar answered Oct 27 '22 22:10

Ali Gangji