PHP HTML generating PDF
Advertisements
1. FPDF: PDF generator
FPDF is a pure PHP class to generate PDF through the document, the method needs to generate content directly in the PHP code to specify, generate text, images, lines, etc., have their own ways. Here use FPDF to generate a "Hello World" of the PDF document:
<?php require(‘fpdf.php’); $pdf=new FPDF(); $pdf->AddPage(); $pdf->SetFont(‘Arial’,'B’,16); $pdf->Cell(40,10,’Hello World!’); $pdf->Output(); ?>
To generate PDF documents, first of all we need to include the library file fpdf.php.
Then we need to create a FPDF object using the default constructor FPDF (), this structure can be three values that the page orientation (portrait or landscape), measurement unit, and the page size (A4, A5 ... ...), by default, page size is A4, units of measurement are millimeters.
It can also be clearly specified:
$pdf=new FPDF(‘P’,'mm’,'A4′);
Then AddPage () function to add a page, the top left corner and the content of the page by default for the 1 cm margin, of course, we can use SetMargins () to change. To generate a text, we need to use the SetFont () to select a font and font size.
$pdf->SetFont(‘Arial’,'B’,16);
We use Cell () function to output a text. A Cell () is a rectangular area containing the text.
Finally, we close this file and put it out, this is the use of the $ pdf-> Output ();, we can also specify where we want to use the file name, such as the $ pdf-> Output ('sample.pdf ');
Here is a brief analysis of an example, if you want to get more help, you can browse: http://www.fpdf.org
2. HTML2FPDF: HTML to PDF conversion
HTML2FPDF is a PHP class library using the FPDF library HTML files into PDF files. The library consists of three categories namely, PDF format, HTML2FPDF and FPDF composition.
Here are a used to convert HTML HTML2FPDF
<?php
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("sample.html","r");
$strContent = fread($fp, filesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo "PDF file is generated successfully!";
?>
First, we need to include library files html2fpdf.php, use HTML2FPDF () constructor to construct an example.
Then use $ pdf-> AddPage () for the new PDF to add a new page. Then we can use the native PHP function to read a file operation HTML file, the contents of this HTML document passed to the function $ pdf-> WriteHTML ($ strContent), HTML content that was written to the PDF file in the Finally, the same operation and FPDF by output (), file output.
This is just a simple example, if you want to get more help, you can visit: http://html2fpdf.sourceforge.net
Here is the example code for all to download
Attached: php generate PDF commonly used class
FPDF
FPDF this PHP Class allows you to use pure PHP (or rather is not required to use PDFlib) to generate PDF files. It has features that include: choice of unit size, page format and margins; header and footer management; automatic paging; automatic text wrapping and alignment; supports JPEG and PNG image formats; support coloring and file Hyperlink; support TrueType, Type1 and encoding; support page compression.
HTML2PDF
HTML2PDF can transform an HTML text into a printer-friendly PDF file. This PHP script is built upon FPDF PHP script.
TCPDF
TCPDF is used to quickly generate PDF files PHP5 function package. TCPDF based on FPDF be extended and improved. Support UTF-8, Unicode, HTML and XHTML.
html2ps
html2ps able to with a picture, complex tables (including rowspan / colspan), layer / div and css style of the HTML into Postscript and PDF. html2ps on CSS2.1 support is very good and well compatible with incorrect HMTL. It may even be able to convert almost like using CSS designed web site msn.com.
HTML_ToPDF
HTML_ToPDF able to convert any HTML document on any platform, and the printer interface formats are the same PDF document. It includes support for image conversion, use style sheets to customize the PDF files and error handling.
cPdfWriter
cPdfWriter is able to output PDF documents PHP5 class. Based on TCPDF, FPDF, and other related scripts.
dompdf
dompdf is an HTML to PDF conversion tool. Its core is a follow most of CSS2.1 style Rendering engine. dompdf with style-driven, it can download and read external style, the style of individual HTML element tags and style attributes. It also supports projects when the majority of HTML attributes.
Related Posts of PHP HTML generating PDF
-
10 essential ruby gems
10 essential ruby gems Author:, source: yeeyan translation of words and the responsibility of Editor: Li Yu, 2008-02-14 11:02 At the time I programmed some things are necessary. So I summed up the 10 most important ruby gems list, they will make your ...
-
Flex framework Riawave applications, as well as the development framework for AJAX consider
Jbpmside want to use Flex to develop the design flow, as well as manager, just an internal company also applied to the Flex, has spent approximately a week to acquaint themselves with and understanding of Flex. Found that one of Flex development and ...
-
Firebug Guide (b) --- how to use the Firebug command line API to provide debugging js procedures (on)
Console Tab Overview This tag is mainly used to print the log only. It can also be a time when debugging in javascript as a command-line window to use (similar to Microsoft Visual Studio in the window immediately (immediate window)). And the use of its
-
Let Ruby On Rails into the Enterprise Development - Export to PDF form
Enterprise development will certainly involve a large number of forms to form, these forms are generally true business information in paper form of implementation. Small enough to leave the list to fill a large list of millions of borrowers to fill, ...
-
Ruby User's Guide>> Getting started
First, you have to check whether the installed ruby. Shell from the start (here "%" express, do not play the%), into the (-V enable ruby interpreter print version), then press Enter. If the ruby has been installed, you will see the followin ...
-
The second stage of examination (HTML.Servlet.JSP.Javascript.Ajax.JQuery)
------------------------------------- Following is the pen questions (questions 2 points each) --- --------------------------------------------- 1. The use of HTTP protocol client request sent to the server-side which has two ways? Please describe briefly
-
in `require ': no such file to load - date / format
Learn today ruby, the ruby download and install, and then began to refer to the relevant entry-tutorial section of a small process running directly on the command line: ruby-e "print 'hello, yiditushe'", after the carriage return, prompt
-
hibernate how to store binary, image and other major fields.
model categories: reportByte binary type for the database fields. public class PfReportStyle implements java.io.Serializable , Cloneable { // Fields /** * */ private static final long serialVersionUID = 1L; private Long id; private byte[] reportByte; // C
-
hibernate study of the second
Persistence of three main points: 1, a statement for persistent fields accessors (accessors) and whether the variable signs (mutators) Property statement is not necessarily required for the public's. Hibernate can be default, protected or private ...
-
First Hibernate Example
Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co












