From Cloudrexx Development Wiki
Jump to: navigation, search

This entry describes the usage of the Cloudrexx component "PDF". It uses mPDF to create PDFs based on templates. It uses the same placeholder syntax as MailTemplate.

Base usage

PDF Template

The following example creates a PDF based on a template and replaces the placeholders "PLACEHOLDER_FOO", "PLACEHOLDER_BAR" and the placeholder "PLACEHOLDER _IN_BLOCK_FOO" withing the block "BLOCK_FOO":

$pdf = $cx->getComponent('Pdf');
$pdfTemplateId = // ID of a PDF template which has been created under "Administration" > "Global Configuration" > "PDF Templates".
$substitution = array(
    'PLACEHOLDER_FOO' => 'Hello',
    'PLACEHOLDER_BAR' => 'World',
    'BLOCK_FOO' => array(
        0 => array(
            'PLACEHOLDER_IN_BLOCK_FOO' => 'Test',
$file = $pdf->generatePDF($pdfTemplateId, $substitution, 'pdf', true);
echo $file['filePath'];
echo $file['fileName'];

Manually create a PDF

The following example creates a PDF based on the HTML code in $tplContent without any substitution:

$pdf = new \Cx\Core_Modules\Pdf\Model\Entity\PdfDocument();
$pdf->SetTitle($fileName . '.pdf');
$pdf->setFilePath($session->getTempPath() . '/' . $fileName . '.pdf');

Custom fonts

1. Upload your custom TrueType font files to the fonts directory (/media/Pdf/ttfonts)

2. The font must be named as follows [1]:

  • MyFont-Regular.ttf
  • MyFont-Bold.ttf
  • MyFont-Italic.ttf
  • MyFont-BoldItalic.ttf

3. To use your custom font in HTML or CSS define it by:

  • HTML:
    <p style="font-family: MyFont;">Text in MyFont</p>
  • CSS:
    font-family: MyFont;


  1. Kashida and OTF are not supported yet.