Blog Sections Open

Generating PDF Versions of Evolution CMS Resources with TCPDF

How to generate a PDF version of an Evolution CMS resource with TCPDF while keeping the HTML version reusable.

Sometimes a resource should live as normal web content and also be downloadable as a PDF. The cleanest pattern is to render the resource once, collect the output as HTML, and then hand that same content to a PDF library when the request asks for it.

The original solution used TCPDF and a simple request switch. If the page was opened normally, the script returned HTML. If contentType=pdf was present, it loaded the TCPDF bootstrap and built a PDF from the same content source.

The core idea looked like this:

$doc = $modx->getPageInfo($id, 1, 'content');
$title = $modx->getPageInfo($id, 1, 'pagetitle');
$output = '<h1><center>'.$title['pagetitle'].'</center></h1>' . $doc['content'];

if ($_GET['contentType'] == 'pdf') {
    include $pluginpath.'examples/myexample.php';
} else {
    return $output;
}

That is a sensible Evolution pattern because it avoids maintaining two separate versions of the same document. Editors work with one resource, while the site exposes two delivery formats.

If you adapt it today, keep paths configurable, sanitize incoming document IDs, and make sure the HTML fed into TCPDF is simplified enough for reliable rendering. But the architectural idea still holds up well.

Newer post

Using `@SELECT` Dropdowns Inside MultiTV Configs in Evolution CMS

How to populate a MultiTV dropdown from site_content with an @SELECT query and what to watch for when the list does not behave as expected.

Older post

Saving Yandex Geocoder Coordinates into a TV in Evolution CMS

A reusable pattern for turning an address into Yandex coordinates and saving the result into a template variable.