1. Products
  2.   PDF
  3.   PHP
  4.   mPDF
 
  

Open Source PHP Library for Processing PDF Files

Create, Modify, and Manipulate PDF Documents, Add Tables, Headers & Footers to PDF Files via PHP API.

mPDF is an Open source PHP Library that enables users to create, modify, and manipulate PDF documents inside their own PHP application. The library supports PDF creation from UTF-8 encoded HTML and accepts UTF-8 encoded HTML. It auto-detects RTL characters within a document and Transfers tables, lists, table cell alignment, justified text as well as a full-text reversal for RTL characters. Moreover, it also auto-detects non-RTL characters and displays them in the original order.

The library supports several important basic and advanced features for PDF documents management, such as PDF creation, Bookmarks, CSS style sheets, PDF Page layout, and orientation, inserting tables or nested tables, adding images ( JPG, GIF, PNG, SVG, BMP or WMF format, Text justification, PDF documents security, headers & footers, page numbering, and many more.

.

Previous Next

Getting Started with mPDF

The Official installation method for mPDF library is through composer packagist package mpdf/mpdf. Please use the following command for a smooth installation.

Install mPDF via composer

$ composer require mpdf/mpdf

PDF Files Creation from UTF-8 Encoded HTML

mPDF library provides functionality for creating PDF documents from UTF-8 encoded HTML inside PHP application. UTF-8 encoded HTML is accepted as the standard input. Once the PDF file is created, you can also make changes to it according to your own needs. The library facilitates you to insert new pages, add new content, insert images, use bookmarks, add headers & footers to an existing page, and much more.

Add Tables to PDF via PHP

The open source library mPDF gives software developers the ability to add and modify tables inside a PDF document. The library supports CSS styles for tables/cells and custom attributes adding a horizontal border at the top and bottom of the table. It also includes support for border-collapse (CSS border-collapse:collapse or separate), as well as cellSpacing and cellPadding. Moreover, you can rotate tables, AutosizePermalink, repeating Table Header row on a new page, and many more.

Export HTML Table to PDF via PHP

 require_once __DIR__ . '/vendor/autoload.php';

if(isset($_GET['checkyouraction'])) {

  // Write your Database query here to get $result

  $data = '';
  while($row = mysqli_fetch_array($result)){
    $data .= 'Event Volunteer ID: ' . $row['eventvolunteerID'] . '
'; $data .= 'Event Title: ' . $row['eventTitle'] . '
'; $data .= 'Roll no.: ' . $row['rollno'] . '
'; $data .= 'Event Date: ' . $row['eventDate'] . '
'; $data .= 'Event Time: ' . $row['eventTime'] . '
'; $data .= 'Event Limit: ' . $row['eventLimit'] . '
'; } $mpdf = new \Mpdf\Mpdf(); $mpdf->WriteHTML($data); $mpdf->Output('myfile.pdf', 'D'); }

Add Headers & Footers to PDF File

The mPDF library includes support for adding headers & footers to a PDF document via PHP. The library provides several different ways to set page headers and page footers in a PDF, such as defining a header/footer for the whole document, including images in a header/footer, complex headers/footers with the advantage of HTML code, setting the header/footer at the start of a document and much more.

Create Password Protected PDF Documents

The mPDF library includes complete support for the settings security of PDF documents. The library gives users the ability to determine whether the document is encrypted and what permissions are granted to the user. It also enables you to set a password for opening the PDF document or modifying the PDF document.

 
 English