Configuring and Setting mPDF Properties

An Easy to Use Course

Here we take a look at how we can combine an HTML page and a CSS file as well as setting some specific properties before we generate our PDF with mPDF.

The code below shows a configuration file where we can write the code necessary to:

Calling the configuration file makes it easier to call code stored in separate files - pdfb03_configuration.php

View the PDF


<h1>About Tidalfire</h1>
        <p>Tidalfire provides PDF business tools and services for desktop, 
        web and mobile.</p>
        <h2>PDF Forms</h2>
        <p>Let your business benefit from dynamic PDF forms. 
        Mobile or desktop – convert your paper forms to intelligent, 
        customer friendly documents.</p>
        <h2>PDF Studio</h2>
        <p>PDF Studio™ an all-in-one, easy to use PDF editor 
        that provides all the features needed at a fraction of the cost of 
        Adobe® Acrobat® and other editors.</p>
        <h2>PDF Automation Server</h2>
        <p>PDF Automation Server (PAS) automates the receiving, processing 
        and routing of documents helping to streamline your 
        document workflows.</p>
        <h3>Contact Details</h3>

CSS Code

h1, h2, h3, p 
            font-family: Arial;
        h2, h3

mPDF Configuration File Code

    //Define a PHP variable with mPDF page number, date and some text
        $footertext='{PAGENO} - {DATE j-m-Y} - Wamazoola Forms';
        require_once __DIR__ . '../../../../../mpdf7/vendor/autoload.php';
        $mpdf = new \Mpdf\Mpdf();
    //Get the location of the external style sheet
        $stylesheet = file_get_contents('pdfb03_styles.css');
    //Get the location of the HTML file
        $html = file_get_contents('pdfb03_basic.php');
    //Set the Title, Author and Subject properties
        $mpdf->SetTitle('Title goldenchild');
        $mpdf->SetAuthor('Author goldenchild');
        $mpdf->SetSubject('Subject goldenchild');
    //Set the display magnification
    //Apply a Watermark
        $mpdf->SetWatermarkText('PREVIEW ONLY');
        $mpdf->showWatermarkText = true;
    //Create bookmarks from the HTML tags and apply a hierarchy
        $mpdf->h2bookmarks = array('H1'=>0, 'H2'=>1, 'H3'=>2);
    //Apply the footer

All code on this site can be used without warranty.

Copyright © 2019