How to access rendered html code before it's passed to PdfReactor8 when view auto render of the FrontendController has been enabled?

How to access rendered html code before it’s passed to PdfReactor8 when view auto render of the FrontendController has been enabled?

For example when I override FrontendController’s renderView, renderTemplate and render methods they are never called.

And via registering kernel.event_listener’s event pimcore.document.renderer.post_render you only get ElementEventInterface/DocumentEvent as parameter for the listening function via which I cannot find a way to access the result html code…

Also when overriding the renderView, renderTemplate and render methods of my controller I only get errors/exceptions as result when view auto render is disabled though the method implementations are directly calling parent implementations…

Hi,
with this event you have access to $reactorConfig['document'] … which contains the HTML.

BR
Christian

But @fash the parameter I receive in the listening function is

Pimcore\Event\Model\PrintConfigEvent

without reactor config… Howto?

its added as parameter, see https://github.com/pimcore/pimcore/blob/c3a7555529423022bdc3d63ee1c9240cf95b1f6a/lib/Web2Print/Processor/PdfReactor8.php#L138

1 Like

Thank you @fash, works like a charm so here’s the code to log html before rendering to pdf!

Resources/config/services.yml:

services:

    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    # Listeners
    MyBundles\PdfBundle\Event\PrintProcessorListener:
        tags:
            - { name: kernel.event_listener, event: pimcore.document.print.processor.modifyConfig, method: onModifyConfig }

PrintProcessorListener.php:

namespace MyBundles\PdfBundle\Event;

use Pimcore\Event\Model\DocumentEvent;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Web2Print\Processor\PdfReactor8;
use Pimcore\Event\Model\PrintConfigEvent;

class PrintProcessorListener
{
    /**
     * Implements logging html document before rendering into pdf when debug mode enabled
     *
     * @param \Pimcore\Event\Model\PrintConfigEvent $event
     */
    public function onModifyConfig(\Pimcore\Event\Model\PrintConfigEvent $event)
    {
        $argument = $event->getArgument("reactorConfig");
        if($argument["enableDebugMode"]) {
            \Pimcore\Log\Simple::log("rendered-html-document", $argument["document"]);
        }
    }
}
1 Like