Convert HTML TO PDF Using PHP

Convert html to pdf using php

Convert html to PDF using PHP, very simple and very best way. Apply any design you wish. There are a lots of APIs to convert HTML to PDF, But as for as I think the MPDF class is really awesome, it has lots of features that other libraries don`t.

About MPDF :

mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF, with a number of enhancements, and enhanced features.

mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML

Supported Features:

  •  UTF-8 encoded HTML
  •  Almost all languages including RTL (arabic and hebrew), and CJK – (chinese-japanese-korean)
  •  Bookmarks
  •  CSS stylesheets
  •  Embedded font subsets
  •  Word spacing and character spacing for justification
  •  Nested block-level elements (e.g. P, DIV) including margins, borders, padding, line-height, background colours etc.
  •  Page layout and orientation
  •  Page numbering
  •  Odd and even paging with mirrored margins
  •  Page headers & footers
  •  Columns
  •  Tables – nested tables, rotated, or autosized to fit on a page
  •  Text-justification and hyphenation
  •  Table of contents
  •  Index
  •  Images as JPG GIF PNG WMF SVG
  •  Watermarks
  •  Password protection.

More Details:

Lets move to practice now.

You can download latest MPDF vesion from here. Other wise you simply download source code from Here , where I have already stored MPDF library along with my code.


Include MPFD Libarary  (Required)

Include css file if you want to add custom style (Optional)

Create object of  mPDF  class.

Complete Code Here :

Create file with PHP extension like index,php

Download Source code 

4 Comments on "Convert HTML TO PDF Using PHP"

  1. You r doing fantastic, Thanks for this,
    It will really helpful

  2. Thanks to you too Victor.

  3. Nice tool.
    Another free tool that I used to create pdf file with php is fpdf:

  4. Very Nice tool. I personally like TCPDF as it allows a clean editable PDF from a HTML form that can be submitted via a PHP script and sent as an attachment via PHPMailer. It is very well documented with hundreds of samples included.

Leave a comment

Your email address will not be published.