1Jan

Html2pdf Php Library

Html2pdf Php Library Average ratng: 6,8/10 7469 reviews

MPDF is a PHP library which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF with a number of enhancements. The original author, Ian Back, wrote mPDF to output PDF files ‘on-the-fly’ from his website, handling different languages.

PDF file format is very useful to download bulk data in the web application. It helps the user to download dynamic content in file format for offline use. With export to PDF functionality, the HTML content is converted to PDF document and downloaded as a PDF file. In the dynamic web application, a server-side script is used to convert HTML to PDF and generate PDF file using PHP.

If you want a client-side solution to generate PDF document, JavaScript is the easiest way to convert HTML to PDF. There are various JavaScript library is available for generating PDF from HTML. jsPDF is one of the best library to convert HTML to PDF using JavaScript. In this tutorial, we will show you how to generate PDF document and convert HTML to PDF using jQuery and jsPDF library.

Include jQuery and jsPDF Library

Include the jQuery and jsPDF library files to use the jsPDF class.

Note that: You don’t need to download the jsPDF library separately, all the required files are included in our source code package.

Instantiate jsPDF Class

Use the following line of code to instantiate and use the jsPDF object in JavaScript.

Generate PDF using JavaScript

The following example shows how to use the jsPDF library to generate PDF file using JavaScript.

  • Specify the content in text() method of jsPDF object.
  • Use the addPage() method to add new page to PDF.
  • Use the save() method to generate and download PDF file.

Convert HTML Content to PDF using JavaScript

The following example shows how to use the jsPDF library to convert HTML to PDF and generate PDF file from HTML content using JavaScript.

  • Retrieve the HTML content from the specific element by ID or class.
  • Convert HTML content of the specific part of the web page and generate PDF.
  • Save and download the HTML content as a PDF file.

HTML Code:

JavaScript Code:

Useful Configurations

The jsPDF library provides various methods and options to configure the PDF creation. Some of the useful methods of jsPDF class are given below that are commonly used to export HTML to PDF using jQuery.

Change Paper Orientation:
Use the orientation option to set the paper orientation of the PDF.

Change Text Font:
Use setFont() and setFontType() methods to set text font and font-style in the PDF.

Change Font Size:
Use setFontSize() method to set font size of the text in the PDF.

Change Text Color:
Use setTextColor() method to set the color of the text in the PDF.

Optitex 11.0 Full Cracked Download. Optitex 11.0 Full Cracked Download Optitex is the leading provider of integrated 2D CAD and 3D digital product solutions for th. How to install optitex 11 crack.

Create PDF with Watermark in PHP using Dompdf

Conclusion

Our example code helps you to convert HTML to PDF and generate PDF file using JavaScript. You can easily add the Export to PDF functionality in the web page without depending on the server-side script. The PDF creation functionality can be enhanced with jsPDF configuration options as per your needs. Download our source code package to get all the required files including jsPDF JavaScript library.

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request