André Amorim

Crafting Web Experiences

//

mPDF Loader

Load mPDF globally for WordPress snippets, themes, or other plugins.

  • Activate AFCA mPDF Loader plugin once.
  • Use the afca_mpdf() function anywhere in WordPress to get a ready mPDF instance.

Installation

  1. Using the ZIP (recommended):
  • Go to Plugins → Add New → Upload Plugin.
  • Upload afca-mpdf-loader.zip.
  • Activate it.
  1. For development / updating dependencies:
composer install

Run this in the plugin root directory to install or update mPDF. (This step is only needed if you are modifying the plugin or updating dependencies.)

Usage Example

add_action('init', function() {
    $mpdf = afca_mpdf([
        'format' => 'A4',
        'margin_left' => 15,
        'margin_right' => 15,
    ]);

    $mpdf->WriteHTML('<h1>Hello from AFCA mPDF!</h1>');

    $upload_dir = wp_upload_dir();
    $file = $upload_dir['basedir'] . '/example.pdf';
    $mpdf->Output($file, \Mpdf\Output\Destination::FILE);
});

Notes

  • $mpdf = afca_mpdf($config_array) returns a fully configured mPDF instance.
  • You can use it for generating PDFs in snippets, plugins, or theme templates.
  • If afca_mpdf() already exists, a debug notice will be logged (requires WP_DEBUG = true).

Published date:

Modified date: