HTML To PDF Convertion in PHP Using MPDF


Introduction


       mPDF is a simple and popular tool for shared hosting users to create and convert UTF-8 encoded HTML pages to PDF files. In other words mPDF is a PHP classes based on FPDF and HTML2PDF tools which purpose is the same – to create and manage PDF documents using simple PHP.

First of all download the mPDF library from here

You can use the following code:



    <?php
    
        $mpdf=new mPDF('c','A4','','' , 23 , 23 , 23 , 23 , 0 , 0); 
        
        $mpdf->SetDisplayMode('fullpage');
        
        $mpdf->list_indent_first_level = 0;    // 1 or 0 - whether to indent the first level of a list
        
        $fileName = '$$pdfName.pdf';        // the pdf fileName
        
        $mpdf->WriteHTML('$$htmlContent');     // the html page which is to be converted to pdf
        
        $mpdf->Output($fileName, 'D');
    ?>
    
    




4 comments:

  1. Thanks for sharing this interesting blog with us.My pleasure to being here on your blog..I wanna come beck here for new post from your site.
    PHP Institutes in Chennai
    PHP Training Center in Chennai

    ReplyDelete
  2. You are doing a great job. I would like to appreciate your work for good accuracy
    Regards,
    PHP Training in Chennai | PHP Course in Chennai

    ReplyDelete

Technologies

1. Nodejs
  • Express
  • Loopback
  • SailsJs
2. Angular
  • 2
  • 4
  • 5
  • 8
3. JQuery
4. PHP
  • LAMP
  • Codeigniter
  • Lumen
5. Database
  • MySQL
  • PostgreSQL
  • MongoDB
6. Artificial Intelligence
  • IBM Watson API
7. Amazon
  • S3
  • EC2
  • SES
  • ELB
8. REST & SOAP API integrations
9. Push notifications
  • FCM - Android
  • APNS - IOS
10. RETS(Real estate domain) servers
11. Standard Implementations
  • 508
  • LTI