This article mainly introduces the methods for generating PDF using the MPDF class in PHP. For more information, see the requirements of the company's business. Recently, we need to generate pdf for html static files, I found a lot of files on the Internet for implementation, and the results were not very good. the first use of tcpdf is particularly slow, and the current version has a very troublesome problem-the background images in css cannot be obtained, and a lot of information cannot be solved. finally, we found that mpdf may be able to implement this function, which is more efficient than tcpdf.
Mpdf official: http://www.mpdf1.com/mpdf/download
Download there are instances, you can refer to do a know. of course, the official website also has an instance, Web site: http://mpdf1.com/common/mpdf/examples/
Official documentation: http://mpdf1.com/manual/
<? Php/** function: generate the user diagnosis Report PDF file * creation Time: -- * // phpinfo (); exit; // introduce the MPDF class file set_time_limit (); include '/include/MPDF/mpdf. php '; // instantiate mpdf $ mpdf = new mPDF ('utf-', 'A', '', '',); // set the font, solve Chinese garbled characters $ mpdf-> useAdobeCJK = true; $ mpdf-> SetAutoFont (AUTOFONT_ALL); // obtain the expected static file: html#file_get_contents('template.html '); echo $ html; exit; // Set the PDF header content $ header ='
'; // Set the content of the PDF footer $ footer ='
|
Footer |
Page Number: {PAGENO}/{nb} |
'; // Add the header and footer to the pdf file $ mpdf-> SetHTMLHeader ($ header); $ mpdf-> SetHTMLFooter ($ footer ); // Set the pdf display mode $ mpdf-> SetDisplayMode ('fullpage'); // Set the pdf size to mm * mm // $ mpdf-> WriteHTML ('
'); // Create a pdf file $ mpdf-> WriteHTML ($ html); // delete the first page of the pdf file (one more page due to setting the pdf size) // $ mpdf-> DeletePages (,); // Output pdf $ mpdf-> Output (); exit;?>