PDF Export in php

2019-01-13 02:23发布

问题:

Is there any possibility to write huge data in pdf without changing any ini modifications with less executing time..?

Currently I'm using tcpdf plugin.

回答1:

If your intention is to create a PDF from PHP, pdflib will help you.

Otherwise, if you want to convert an HTML page to PDF via PHP, you'll find a little trouble outta here.

So, the options I know are:

DOMPDF : PHP class that wraps the HTML and builds the PDF. Works good, customizable (if you know PHP), based on pdflib, and, if I remember correctly, it takes even some CSS. Bad news: slow when the HTML is big or very complex.

HTML2PS: same as DOMPDF, but this one converts first in .ps (GhostScript), then, in whatever format you need (PDF, JPEG, PNG). For me it is a little better then 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), it's really fast and powerful. Seems like it is the best one (at the moment) for HTML to PDF conversion on the fly, taking only 2 seconds for a 3 page XHTML document with CSS2. It's a recent project anyway, so the google.code page is often updated.

htmldoc : this one is a tank, it really never stops/crashes. The project seems dead, as of 2007, but if you don't need CSS compatibility this can be nice for you.

tcpdf - this is an enhanced and maintained version of fpdf. It has all the main Features of tpdf and it also has faster execution time with great output. For detailed tutorial on using the two most popular PDF generation classes: TCPDF and FPDF, please follow this link. I think you should continue using TCPDF.

See these 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. How to convert html into pdf with php?
  6. Tool for exporting html as pdf
  7. Converting HTML in PHP File to PDF File


回答2:

I highly recommend FPDF, very easy to use and you don't need any modifications.



回答3:

I've been using DOMPDF http://code.google.com/p/dompdf/ as it handles HTML/CSS very well.



回答4:

You should use Webkit HTML to PDF http://code.google.com/p/wkhtmltopdf/

It simply requests the HTML page (generated from your PHP) and renders it to PDF (using the Webkit rendering engine, which is one of the best).

Hence it requires no extra resources on the PHP side.



回答5:

http://www.phpclasses.org/package/6638-PHP-Generate-a-PDF-file-with-a-listing-of-data-records.html



回答6:

You could just use Zend Framework. If I'm not mistaken, there is a feature in the framework that allows you to create PDF's.