PHP is now the best plugin to generate PDF files, today introduced in the ThinkPHP3.2.3 how to use.
First, the path is set.
Here's how to use
- Public function PDF() {
- //Introduction of Class library
- Vendor(' mpdf.mpdf ');
- //Set Chinese encoding
- $mpdf=new \mpdf(' ZH-CN ',' A4 ', 0, ' Arial ', 0 , 0);
- //html Content
- $html=' ;
- $mpdf-writehtml($html);
- $mpdf, Output();
- exit;
- }
Copy
Enter in the browser
- XXX/index. PHP? s=/home/Index/PDF //Replace with your URL path
Copy
The effect is as follows
Here are some advanced ways to use it:
- Public function PDF() {
- //Introduction of Class library
- Vendor(' mpdf.mpdf ');
- //Set Chinese encoding
- $mpdf=new \mpdf(' ZH-CN ',' A4 ', 0, ' Arial ', 0 , 0);
- $mpdf-setwatermarktext(' China watermark ',0.1);
- $strContent = ' I am a PDF file with watermarks ';
- $mpdf-showwatermarktext = true;
- $mpdf-Sethtmlheader( ' head ' );
- $mpdf-sethtmlfooter( ' bottom ' );
- //$stylesheet =file_get_contents (' themes/wei/css/bootstrap.min.css ');
- //$mpdf->writehtml ($stylesheet, 1);
- $mpdf-writehtml($strContent);
- //Save Ss.pdf file
- $mpdf, Output(' ss.pdf ');
- //Direct browser output PDF
- $mpdf, Output(' tmp.pdf ',true);
- $mpdf, Output(' tmp.pdf ',' d ');
- $mpdf, Output();
- exit;
- }
Copy
Mpdf download can be downloaded to the official website http://www.mpdf1.com or in the following Baidu cloud download
ThinkPHP3.2.3 expanded PDF file (MPDF)