Php method for generating PDFs using the Mpdf class _php instance

Source: Internet
Author: User
Due to the company's business needs, the recent need to create a PDF of HTML static files, found on the internet a lot of class files to achieve, the effect is not very good. The first use of tcpdf this class is particularly slow, and the current version has a very annoying problem-css background image can not be obtained, Find a lot of information can not be solved. Finally found that mpdf may achieve this function, overjoyed, and efficiency is faster than tcpdf.

Mpdf's official download address: Http://www.mpdf1.com/mpdf/download

After the download there are instances, you can refer to do one to know. Of course, the official website also has examples, website: http://mpdf1.com/common/mpdf/examples/

Documents provided by the Government: http://mpdf1.com/manual/

<?php/** function: Generate user Diagnostic report PDF file * Creation time:--*///phpinfo (); exit;//introduces MPDF class file Set_time_limit (); include '/include/mpdf/ Mpdf.php ';//Instantiate Mpdf$mpdf=new mpdf (' utf-', ' A ', ' ', ' Arial ',,,,);//Set font, solve Chinese garbled $mpdf->useadobecjk = true; $mpdf Setautofont (Autofont_all);//Gets the static file to generate $html=file_get_contents (' template.html '); echo $html; exit;//Set PDF header contents $ Header= '
 
 
Header
';//Set PDF footer Content $footer= '
Footer Page number: {PAGENO}/{NB}
///Add headers and footers to PDF $mpdf->sethtmlheader ($header), $mpdf->sethtmlfooter ($footer),//Set PDF display $mpdf-> Setdisplaymode (' fullpage ');//Set the PDF size to mm*mm//$mpdf->writehtml (' ')///Create PDF file $mpdf->writehtml ($html);//delete the first page of PDF (due to the size of the PDF)//$mpdf->deletepages (,);//Output pdf$mpdf- >output (); exit; >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.