Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert html into pdf with php?

I have html in a mysql table and want to turn it into downloadable pdf files.

There are tools to convert files into pdf, but I have not found one that works with php.

Can you help? Any suggestions?

like image 851
user586011 Avatar asked Jan 20 '23 08:01

user586011


2 Answers

If your meaning is to create a pdf from php, pdflib will help you.

Else, if you want to convert an HTML page in pdf via PHP, the options I know are:

DOMPDF : php class that wrap the html and build the pdf. Works good, customizable (if you know php), based on pdflib, if i remember right it takes even some CSS. Bad news: slow when the html is big or complex.

HTML2PS: same of DOMPDF, but this one convert first in .ps (ghostscript), then, in whatever format you need (pdf, jpg, png). For me this is little better than dompdf, but have the same speed problem.. oh, better compatibility with css.

Those two are php classes, but if you can install some software on the server, and access it through passthru() or system(), give a look to these too:

wkhtmltopdf: based on webkit (safari's wrapper), is really fast and powerful.. seem like is the best one (atm) for convert on the fly html pages to pdf, taking only 2 seconds for a 3 pages xHTML document with CSS2. Is a recent project, anyway, the google.code page is often updated.

htmldoc : this one is a tank, it really never stop/crash.. the project seem death in the 2007, but anyway if you don't need css compatibility this can be nice for you.

tcpdf - this is an enhanced and maintained version of fpdf. Main Features of tcpdf and it is also having less execution time with great output. For a detailed tutorial on using the two most popular pdf generation classes: TCPDF and FPDF. Please follow this link.

See this posts also.

  1. Convert HTML + CSS to PDF with PHP?
  2. Which one is the best PDF-API for PHP?
  3. Export a html into PDF in PHP?
  4. Writing HTML with PHP variables to PDF file?
  5. Tool for exporting html as pdf
  6. Converting HTML in PHP File to PDF File
like image 150
Somnath Muluk Avatar answered Jan 29 '23 03:01

Somnath Muluk


DOMpdf is the best free one.

If money isn't an issue, PrinceXML is best.

like image 44
alex Avatar answered Jan 29 '23 04:01

alex