2017 © Pedro Peláez
 

library mpdf

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

image

niklasravnsborg/mpdf

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  • Saturday, April 23, 2016
  • by niklasravnsborg
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2,463 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 445 Forks
  • 0 Open issues
  • 17 Versions
  • 1 % Grown

The README.md

mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML. It is based on FPDF and HTML2FPDF (see CREDITS), with a number of enhancements. mPDF was written by Ian Back and is released under the GNU GPL v2 licence., (*1)

Installation

  • Download the .zip file and unzip it
  • Create a folder e.g. /mpdf on your server
  • Upload all of the files to the server, maintaining the folders as they are
  • Ensure that you have write permissions set (CHMOD 6xx or 7xx) for the following folders:, (*2)

    /ttfontdata/ - used to cache font data; improves performance a lot, (*3)

    /tmp/ - used for some images and ProgressBar, (*4)

    /graph_cache/ - if you are using JpGraph in conjunction with mPDF, (*5)

To test the installation, point your browser to the basic example file:, (*6)

[path_to_mpdf_folder]/mpdf/examples/example01_basic.php

If you wish to define a different folder for temporary files rather than /tmp/ see the note on Folder for temporary files in the section on Installation & Setup in the manual., (*7)

If you have problems, please read the section on troubleshooting in the manual., (*8)

Fonts

Let us refer to font names in 2 ways:, (*9)

  1. "CSS font-family name" - mPDF is designed primarily to read HTML and CSS. This is the name used in CSS e.g., (*10)

    <p style="font-family: 'Trebuchet MS';">, (*11)

  2. "mPDF font-family name" - the name used internally to process fonts. This could be anything you like, but by default mPDF will convert CSS font-family names by removing any spaces and changing to lowercase. Reading the name above, mPDF will look for a "mPDF font-family name" of:, (*12)

    'trebuchetms', (*13)

The configurable values referred to below are set in the config_fonts.php file., (*14)

When parsing HTML/CSS, mPDF will read the CSS font-family name (e.g. 'Trebuchet MS') and convert by removing any spaces and changing to lowercase, to look for a mPDF font-family name (trebuchetms)., (*15)

Next it will look for a translation (if set) in config_font.php e.g.:, (*16)

$this->fonttrans = array(
    'trebuchetms' => 'trebuchet'
)

Now the mPDF font-family name to be used is 'trebuchet', (*17)

If you wish to make this font available, you need to specify the Truetype .ttf font files for each variant. These should be defined in config_font.php in the array:, (*18)

$this->fontdata = array(
    "trebuchet" => array(
        'R' => "trebuc.ttf",
        'B' => "trebucbd.ttf",
        'I' => "trebucit.ttf",
        'BI' => "trebucbi.ttf",
        )
)

This is the array which determines whether a font is available to mPDF. Each font-family must have a Regular ['R'] file defined - the others (bold, italic, bold-italic) are optional., (*19)

mPDF will try to load the font-file. If you have defined _MPDF_SYSTEM_TTFONTS at the top of the config_fonts.php file, it will first look for the font-file there. This is useful if you are running mPDF on a computer which already has a folder with TTF fonts in (e.g. on Windows), (*20)

If the font-file is not there, or _MPDF_SYSTEM_TTFONTS is not defined, mPDF will look in the folder, (*21)

/[your_path_to_mpdf]/ttfonts/

Note that the font-file names are case-sensitive and can contain capitals., (*22)

If the folder /ttfontdata/ is writeable (CHMOD 644 or 755), mPDF will save files there which it can re-use next time it accesses a particular font. This will significantly improve processing time and is strongly recommended., (*23)

mPDF should be able to read most TrueType Unicode font files with a .ttf extension. Truetype fonts with .otf extension that are OpenType also work OK. TrueType collections (.ttc) will also work if they contain TrueType Unicode fonts., (*24)

Character substitution

Most people will have access to a Pan-Unicode font with most Unicode characters in it such as Arial Unicode MS. Set:, (*25)

$this->backupSubsFont = array('arialunicodems');

at the top of the config_fonts.php file to use this font when substituting any characters not found in the specific font being used., (*26)

Example: You can set:, (*27)

$mpdf->useSubstitutions = true;

at runtime, or, (*28)

$this->useSubstitutions = true;

in the config.php file, (*29)

This text contains a Thai character ม which does not exist in the Comic Sans MS font file, (*30)

When useSubstitutions is true, mPDF will try to find substitutions for any missing characters: 1) firstly looks if the character is available in the inbuilt Symbols or ZapfDingbats fonts; 2) [If defined] looks in each of the the font(s) set by $this->backupSubsFont array, (*31)

NB There is an increase in processing time when using substitutions, and even more so if a backupSubsFont is defined., (*32)

Controlling mPDF mode

The first parameter of new mPDF('') works as follows:, (*33)

  • new mPDF('c') - forces mPDF to only use the built-in [c]ore Adobe fonts (Helvetica, Times etc), (*34)

  • new mPDF('') - default - font subsetting behaviour is determined by the configurable variables $this->maxTTFFilesize and $this->percentSubset (see below), (*35)

    Default values are set so that: 1) Very large font files are always subset 2) Fonts are embedded as subsets if < 30% of the characters are used, (*36)

  • new mPDF('..+aCJK'), (*37)

    new mPDF('+aCJK'), (*38)

    new mPDF('..-aCJK'), (*39)

    new mPDF('-aCJK'), (*40)

    Used optionally together with a language or language/country code, +aCJK will force mPDF to use the Adobe non-embedded CJK fonts when a passage is marked with e.g. "lang: ja", (*41)

    This can be used at runtime to override the value set for $mpdf->useAdobeCJK in config.php, (*42)

    Use in conjunction with settings in config_cp.php, (*43)

For backwards compatibility, new mPDF('-s') and new mPDF('s') will force subsetting by setting, (*44)

$this->percentSubset=100

new mPDF('utf-8-s') and new mPDF('ar-s') are also recognised, (*45)

Configuration variables changed

Configuration variables are documented in the on-line manual., (*46)

Font folders

If you wish to define your own font file folders (perhaps to share), you can define the 2 constants in your script before including the mpdf.php script e.g.:, (*47)

define('_MPDF_TTFONTPATH','your_path/ttfonts/');
define('_MPDF_TTFONTDATAPATH','your_path/ttfontdata/');     // should be writeable

Unit Testing

Unit testing for mPDF is done using PHPUnit., (*48)

To get started, run composer install from the command line while in the mPDF root directory (you'll need composer installed first)., (*49)

To execute tests, run ../vendor/bin/phpunit from the command line while in the mPDF /tests/ directory., (*50)

Any assistance writing unit tests for mPDF is greatly appreciated. If you'd like to help, please note that any PHP file located in the /tests/ directory will be autoloaded when unit testing., (*51)

The Versions

23/04 2016

dev-development

dev-development http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Ian Back

php utf-8 pdf

14/03 2016

v6.1.0

6.1.0.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Ian Back

php utf-8 pdf

14/03 2016

6.1.0-beta

6.1.0.0-beta http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

by Ian Back

php utf-8 pdf

17/06 2015

6.1.x-dev

6.1.9999999.9999999-dev http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

The Development Requires

by Ian Back

php utf-8 pdf

17/06 2015

7.0.x-dev

7.0.9999999.9999999-dev http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

The Development Requires

by Ian Back

php utf-8 pdf

17/06 2015

dev-master

9999999-dev http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-2.0

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

The Development Requires

by Ian Back

php utf-8 pdf

01/03 2015

v6.0.0

6.0.0.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

17/12 2014

v5.7.4a

5.7.4.0-alpha http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

14/12 2014

v5.7.4

5.7.4.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

22/09 2014

v5.7.3a

5.7.3.0-alpha http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

24/08 2014

v5.7.3

5.7.3.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

16/05 2014

v5.7.2

5.7.2.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

07/01 2014

v6.0-beta

6.0.0.0-beta http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10
  • ext-mbstring *

 

by Ian Back

php utf-8 pdf

02/09 2013

v5.7.1

5.7.1.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10

 

by Ian Back

php utf-8 pdf

18/07 2013

v5.7.0

5.7.0.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10

 

by Ian Back

php utf-8 pdf

26/01 2013

v5.6.1

5.6.1.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10

 

by Ian Back

php utf-8 pdf

20/11 2012

v5.5.1

5.5.1.0 http://www.mpdf1.com/mpdf/index.php

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support

  Sources   Download

GPL-1.0+

The Requires

  • php >=4.3.10

 

by Ian Back

php utf-8 pdf