printArticleAsPdf

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.

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\ServiceAnnotation\Hook;
use Contao\ModuleArticle;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class PrintArticleAsPdfListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("printArticleAsPdf")
     */
    public function onPrintArticleAsPdf(string $articleContent, ModuleArticle $module)
    {
        // Trigger your own PDF engine and exit
        exit;
    }
}

References