printArticleAsPdf

Details

This page shows version 4.x. The current version can be found here.

The printArticleAsPdf hook is triggered when an article should be exported as PDF. It passes the article text and the article object as arguments and does not expect a return value. Use it to override the internal PDF functionality.

Note

Using the printArticleAsPdf hook has been deprecated and will no longer work in Contao 5.0.

Parameters

  1. string $articleContent

    The compiled article content.

  2. \Contao\ModuleArticle $module

    Instance of the \Contao\ModuleArticle module responsible for producing the front end output of an article.

Example

// src/EventListener/PrintArticleAsPdfListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\ModuleArticle;

#[AsHook('printArticleAsPdf')]
class PrintArticleAsPdfListener
{
    public function __invoke(string $articleContent, ModuleArticle $module): void
    {
        // Trigger your own PDF engine and exit
        exit;
    }
}

References