Introduction of several open source projects that use PHP to generate PDF files from HTML

  • 2021-08-03 09:47:18
  • OfStack

Generating PDF files using PHP encoding is a very time-consuming task. In the early days, developers used PHP and used FPDF to generate PDF files. But now, there are many libraries available, and you can generate PDF documents from the HTML files you provide. This makes the previously time-consuming work very simple.

FPDF was used very early, and its characteristics are as follows:

FPDF

FPDF is an PHP class that allows PDF documents to be generated using pure PHP, in other words, without the PDFlib library. F in FPDF stands for free and free: You can use it in any situation and support customization to meet your specific needs

Features:

1. You can select cells, page formats, and margins
2. You can manage headers and footers
3. Automatic paging
4. Word wrapping and text alignment
5. Support pictures (JPEG, PNG, gif)
6. Rich colors and support links

By the way, I also introduce some function libraries that can directly generate PDF from HTML.

DomPDF

domPDF converts HTML to PDF. DomPDF follows the HTML layout of CSS 2.1 and is a rendering engine written in PHP. DomPDF is style-oriented: it downloads and reads the style attribute values for the externally linked style sheet, inline styles, and HTML elements. It also supports most HTML visible properties.

Features:

1. Handle most CSS2.1 and a few CSS3 attributes, including @ import, @ media & @ page rule
2. Supports most of the visible properties of HTML 4.1
3. Support for external style sheets, including local or http/ftp linked (via fopen-wrappers)
4. Support complex table structure, including span and separate for rows and columns & collapsed border models and stand-alone cell styles
5. Support pictures (gif, png, bmp) & jpeg)
6. Independent of other PDF function libraries

TCPDF

TCPDF can also be used to generate PDF documents, and it is an open source PHP class library.
The TCPDF project started in 2002 and is now freely used by thousands of people. TCPDF is a Free Libre Open Source Software (FLOSS).

Features:

1. Basic functions do not depend on other PDF function libraries
2. Standard page format, supporting page format customization, margin customization and unit measurement
3. Support UTF-8 encoding and text direction from right to left language.
4. Support fonts such as TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1, and and CID-0
5. Support font subsets and provide methods to publish 1 XHTML + CSS code, Javascript and Forms
6. Support the conversion of pictures and graphics
7. Support page compression (php-zlib extension is required)
8. Automatically manage headers and footers

For more features, please stamp: more

From the original comment list, I also collected related sites and open source projects:

wkhtmltopdf (commented that it is the standard for HTML to generate PDF):
https://code.google.com/p/wkhtmltopdf/
https://github.com/mreiferson/php-wkhtmltox

pdfservices (this need not be explained, just poke it open):
http://www.pdfservices.net/


Related articles: