手册中介绍PHP生成PDF用的是fpdf,网上也有一些代码其于Fpdf的看起来好象都不错,但是前提是有fpdf。。因此后来都放弃了。
这一个php class我没有试过,但是看上去好象不错,因为:1开源2原生PHP,不用组件(听说,没试过。)主要是看它可以直接把网页生成PDF,因为他支持html,xhtml,css。所以感觉不错
TCPDF is an Open Source PHP class for generating PDF documents.
TCPDF project was started in 2002 and now it is freely used all over the world by millions of people. TCPDF is a Free Libre Open Source Software (FLOSS).
官方的说明也很详细:
Main Features:
- no external libraries are required for the basic functions;(看来也只是针对基本功能,不过我想应该够了。)
- all ISO page formats, custom page formats, custom margins and units of measure;
- UTF-8 Unicode and Right-To-Left languages;
- TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
- Font subsetting;
- methods to publish some XHTML + CSS code, Javascript and Forms;
- images, graphic (geometric figures) and transformation methods;
- native support for JPEG, PNG and SVG images;
- 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, QR-Code, PDF417;
- Grayscale, RGB, CMYK, Spot Colors and Transparencies;
- automatic page header and footer management;
- document encryption and digital signature certifications;
- transactions to UNDO commands;
- PDF annotations, including links, text and file attachments;
- text rendering modes (fill, stroke and clipping);
- multiple columns mode;
- bookmarks and table of content;
- text hyphenation;
- automatic page break, line break and text alignments including justification;
- automatic page numbering and page groups;
- move and delete pages;
- page compression.
这里也还有一些例子,有61个之多:
- Simple PDF with default Header and Footer: [PHP] [PDF]
- Simple PDF without Header and Footer: [PHP] [PDF]
- Custom Header and Footer: [PHP] [PDF]
- Cell stretching: [PHP] [PDF]
- Multicell: [PHP] [PDF]
- WriteHTML and RTL support: [PHP] [PDF]
- Independent columns with WriteHTMLCell: [PHP] [PDF]
- External UTF-8 text file: [PHP] [PDF]
- Image: [PHP] [PDF]
- Multiple columns: [PHP] [PDF]
- Colored Tables: [PHP] [PDF]
- Graphic Functions: [PHP] [PDF]
- Graphic Transformations: [PHP] [PDF]
- Javascript and Forms: [PHP] [PDF]
- Bookmarks (Table of Content): [PHP] [PDF]
- Document Encryption: [PHP] [PDF]
- Independent columns with MultiCell: [PHP] [PDF]
- Persian and Arabic language on RTL document: [PHP] [PDF]
- Non unicode / Alternative config file: [PHP] [PDF]
- Multicell complex alignment: [PHP] [PDF]
- writeHTML alignment: [PHP] [PDF]
- CMYK colors: [PHP] [PDF]
- Page Groups: [PHP] [PDF]
- Object Visibility: [PHP] [PDF]
- Object Transparency: [PHP] [PDF]
- Text Clipping: [PHP] [PDF]
- Barcodes: [PHP] [PDF]
- Multiple page formats: [PHP] [PDF]
- Set PDF viewer display preferences: [PHP] [PDF]
- Colour gradients: [PHP] [PDF]
- Pie Chart Graphic: [PHP] [PDF]
- EPS/AI vectorial image: [PHP] [PDF]
- Mixed font types (TrueType Unicode, core, CID-0): [PHP] [PDF]
- Clipping masks: [PHP] [PDF]
- Line styles with cells and multicells: [PHP] [PDF]
- Text Annotations: [PHP] [PDF]
- Spot Colors: [PHP] [PDF]
- NON-embedded CID-0 CJK font: [PHP] [PDF]
- HTML Justification: [PHP] [PDF]
- Booklet (double-sided pages): [PHP] [PDF]
- File attachment: [PHP] [PDF]
- Image with Alpha Channel Transparency: [PHP] [PDF]
- Disk caching: [PHP] [PDF]
- Move, Copy and delete page: [PHP] [PDF]
- Table Of Content with Bookmarks: [PHP] [PDF]
- Text hyphenation: [PHP] [PDF]
- Transactions and UNDO: [PHP] [PDF]
- Table header and rowspan: [PHP] [PDF]
- TCPDF methods in HTML: [PHP] [PDF]
- 2D Barcode (QR Code): [PHP] [PDF]
- Full page background: [PHP] [PDF]
- Digital Signature Certification: [PHP] [PDF]
- Javascript functions: [PHP] [PDF]
- XHTML Form: [PHP] [PDF]
- Font Dump: [PHP] [PDF]
- Crop Marks and Registration Marks: [PHP] [PDF]
- Cell vertical alignments: [PHP] [PDF]
- SVG Image: [PHP] [PDF]
- Table Of Content with HTML templates: [PHP] [PDF]
- Advanced page settings: [PHP] [PDF]
- XHTML + CSS: [PHP] [PDF]
可以尝试试用一下吧。