Movatterモバイル変換


[0]ホーム

URL:


mPDF Manual – Installation & Setup

Installation v7+

Installation

Official installation method is via composer and its packagist packagempdf/mpdf.

$composer require mpdf/mpdf

Usage

The simplest usage of the library would be as follows:

Warning: mPDF is not meant to receive HMTL/CSS from an outside user.

All user input passed to mPDF should be vetted and sanitized properlyabove the levelof standard browser-level sanitization (such ishtmlspecialchars).

<?phprequire_once__DIR__.'/vendor/autoload.php';$mpdf=new\Mpdf\Mpdf();$mpdf->WriteHTML('<h1>Hello world!</h1>');$mpdf->Output();

Allconfiguration directives canbe set by the$config parameter of theconstructor.

<?php...// Define a page using all default values except "L" for Landscape orientation$mpdf=new\Mpdf\Mpdf(['orientation'=>'L']);...

It is recommended toset custom temporary directoryviatempDir configuration key. The directory must have write permissions (mode775 is recommended).

<?php// Define a page using all default values except "L" for Landscape orientation$mpdf=new\Mpdf\Mpdf(['tempDir'=>__DIR__.'/custom/temp/dir/path']);

If you have problems, please read the section ontroubleshooting in the manual.

Upgrading from older mPDF versions

mPDF 7.x has introduced namespaces, so in order to use mPDF, you have to reference the class either by fullyqualified name:

<?phprequire_once__DIR__.'/vendor/autoload.php';$mpdf=new\Mpdf\Mpdf();

or import the class beforehand:

<?phpuseMpdf\Mpdf;require_once__DIR__.'/vendor/autoload.php';$mpdf=newMpdf();

The class now accepts only one parameter, an array of configuration directives. Seeconfiguration directives for reference.

If you wish to install additional fonts please see the notes inFonts & Languagesfor further instructions.


[8]ページ先頭

©2009-2026 Movatter.jp