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:
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.
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.
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 :
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With