mPDF Manual – Setting PDF file properties

Document Metadata

A PDF file contains metadata about the title, author, subject, creation date, keywords. The title is usually shown in the top of the screen when a user views the file; the rest of the metadata can be accessed by viewing Document properties in Adobe Reader.

You can set the metadata directly using:

Metadata is also set automatically if you pass full HTML code to WriteHTML() including:

  • title is read from <title>...</title> tags
  • subject, keywords and author are read from <meta ... /> tags

Whichever is set later will override previous settings.

The text should be UTF-8 encoded, but should not contain HTML mark-up tags. strcode2utf() is a useful function provided with mPDF which converts HTML numerical entities to UTF-8 encoded string.

Example

<?php
$mpdf = new \Mpdf\Mpdf();

$md = strcode2utf("&#1575;&#1610;&#1604;&#1575;&#1578; &#1601;&#1610;&#1605;&#1575; 
    &#1575;&#1610;&#1604;&#1575;&#1578; &#1601;&#1610;&#1605;&#1575;");
$mpdf->SetTitle($md);

$mpdf->WriteHTML('Hello World');

$mpdf->Output();

See Also

Fork me on GitHub