Styling your PDF with CSS

An Easy to Use Course


Using mPDF and HTML means we can add CSS (Cascading Style Sheets) to format the colour, layout, fonts and more of the PDF output. In this example we add CSS within the HTML code to format the HTML tags. In subsequent examples we will use CSS stored in an external .css file to make the formatting more modular and reusable. View the code of the sample web page
View the PDF
<?php
        //==============================================================
        $html = '
        <style>
        h1, h2, h3, p {
            font-family: Arial;
            color:#f00;
        }
        p {
            font-family: Arial;
            font-style:italic;
            color:#00f;
        }
        </style>
        <body>
        <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>
        
        <p>e: info@tidalfire.com</p>
        ';
        
        //==============================================================
        
        require_once __DIR__ . '../../../../../mpdf7/vendor/autoload.php';
        
        $mpdf = new \Mpdf\Mpdf();
         
        
        $mpdf->WriteHTML($html);
        
        $mpdf->Output();
        
        exit;
        //==============================================================
        
?>

All code on this site can be used without warranty.

Copyright © 2019 osuch.com