mPDF Manual – What Else Can I Do

Layers

(mPDF >= 5.7)

CSS z-index can be used to utilise layers in the PDF document.

CSS can set the z-index for any block element or image (default: 0). This does not work on block elements with fixed or absolute position.

Set the Initial state for each layer

You can set initial 'state' = "hidden" for a specific z-index (z), and/or specify a display name for the Layer e.g.

<?php
// Set initial state of layer: "hidden" or nothing
$mpdf->layerDetails[z]['state'] = 'hidden'; 

<?php
$mpdf->layerDetails[z]['name'] = 'Correct Answers';

  • where z is the z-index (set by CSS)

Note:

  • Using layers automatically changes the resulting PDF document to PDF 1.5 version (which is incompatible with PDFA and PDFX in mPDF).
  • You cannot nest layers - inner values will be ignored

Display the Layers pane in PDF document viewer

$mpdf->open_layer_pane (set by default as 'open_layer_pane' => false as a configuration variable) can be set to open the layers pane in the browser when the document is opened.

<?php
$mpdf->open_layer_pane = true;

Set Programmatically

If you are writing the PDF document using functions other than WriteHTML(), you can set the layers as follows:

<?php

$mpdf->BeginLayer($z-index);

...

$mpdf->EndLayer();

Reserved Layer Names

mPDF automatically adds layer names for visibility: “Print only”, “Screen only” and “Hidden”; these only show when utilised.

Fork me on GitHub