src/Module.php
public function attachPDFtransformer(ViewEvent $e)
    {
        
        //$renderer = $e->getRenderer();
        $result   = $e->getResult();
        $response = $e->getResponse();
        
        // the handles are for temporary files
        error_reporting(0);
        foreach (array(self::RENDER_FULL, self::RENDER_WITHOUT_PDF, self::RENDER_WITHOUT_ATTACHMENTS ) as $render) {
            $handles = array();
            try {
                $pdf = new extern\mPDFderive();
                $pdf->SetImportUse();
                // create bookmark list in Acrobat Reader
                $pdf->h2bookmarks = array('H1' => 0, 'H2' => 1, 'H3' => 2);
                $pdf->WriteHTML($result);

                // Output of the Images
                if (self::RENDER_FULL == $render || self::RENDER_WITHOUT_PDF == $render) {
                    if (is_array($this->appendImage) && !empty($this->appendImage)) {
                        foreach ($this->appendImage as $imageAttachment) {
                            $content = $imageAttachment->getContent();
                            $url = 'data:image/' . $imageAttachment->getType() . ';base64,' . base64_encode($content);
                            $html = '<a name="attachment_' . $imageAttachment->getId() . '"><img src="' . $url . '" /><br /></a>';
                            $pdf->WriteHTML($html);
                        }
                    }
                }

                // Temp Files PDF
                if (self::RENDER_FULL == $render) {
                    if (is_array($this->appendPDF) && !empty($this->appendPDF)) {
                        foreach ($this->appendPDF as $pdfAttachment) {
                            $content = $pdfAttachment->getContent();
                            $tmpHandle = tmpfile();
                            $handles[] = $tmpHandle;
                            fwrite($tmpHandle, $content);
                            fseek($tmpHandle, 0);
                        }
                    }
                }

                // Output of the PDF
                foreach ($handles as $handle) {
                    $meta_data = stream_get_meta_data($handle);
                    $filename = $meta_data["uri"];
                    $pdf->WriteHTML($filename);
                    $pagecount = $pdf->SetSourceFile($filename);
                    for ($pages = 0; $pages < $pagecount; $pages++) {
                        $pdf->AddPage();
                        $pdf->WriteHTML(' pages: ' . $pagecount);
                        $tx = $pdf->ImportPage($pages + 1);
                        $pdf->UseTemplate($tx);
                    }
                }

                $pdf_result = $pdf->Output();
                $e->setResult($pdf_result);

                // delete all temporary Files again
                foreach ($handles as $handle) {
                    fclose($handle);
                }
                break;
            } catch (\Exception $e) {
            }
        }
        error_reporting(E_ALL);
    }
public function attachPDFtransformer(ViewEvent $e)
    {
        
        //$renderer = $e->getRenderer();
        $result   = $e->getResult();
        $response = $e->getResponse();
        
        // the handles are for temporary files
        error_reporting(0);
        foreach (array(self::RENDER_FULL, self::RENDER_WITHOUT_PDF, self::RENDER_WITHOUT_ATTACHMENTS ) as $render) {
            $handles = array();
            try {
                $pdf = new extern\mPDFderive();
                $pdf->SetImportUse();
                // create bookmark list in Acrobat Reader
                $pdf->h2bookmarks = array('H1' => 0, 'H2' => 1, 'H3' => 2);
                $pdf->WriteHTML($result);

                // Output of the Images
                if (self::RENDER_FULL == $render || self::RENDER_WITHOUT_PDF == $render) {
                    if (is_array($this->appendImage) && !empty($this->appendImage)) {
                        foreach ($this->appendImage as $imageAttachment) {
                            $content = $imageAttachment->getContent();
                            $url = 'data:image/' . $imageAttachment->getType() . ';base64,' . base64_encode($content);
                            $html = '<a name="attachment_' . $imageAttachment->getId() . '"><img src="' . $url . '" /><br /></a>';
                            $pdf->WriteHTML($html);
                        }
                    }
                }

                // Temp Files PDF
                if (self::RENDER_FULL == $render) {
                    if (is_array($this->appendPDF) && !empty($this->appendPDF)) {
                        foreach ($this->appendPDF as $pdfAttachment) {
                            $content = $pdfAttachment->getContent();
                            $tmpHandle = tmpfile();
                            $handles[] = $tmpHandle;
                            fwrite($tmpHandle, $content);
                            fseek($tmpHandle, 0);
                        }
                    }
                }

                // Output of the PDF
                foreach ($handles as $handle) {
                    $meta_data = stream_get_meta_data($handle);
                    $filename = $meta_data["uri"];
                    $pdf->WriteHTML($filename);
                    $pagecount = $pdf->SetSourceFile($filename);
                    for ($pages = 0; $pages < $pagecount; $pages++) {
                        $pdf->AddPage();
                        $pdf->WriteHTML(' pages: ' . $pagecount);
                        $tx = $pdf->ImportPage($pages + 1);
                        $pdf->UseTemplate($tx);
                    }
                }

                $pdf_result = $pdf->Output();
                $e->setResult($pdf_result);

                // delete all temporary Files again
                foreach ($handles as $handle) {
                    fclose($handle);
                }
                break;
            } catch (\Exception $e) {
            }
        }
        error_reporting(E_ALL);
    }
Transform the HTML to PDF,
this is a post-rendering-process

put in here everything related to the transforming-process like options

@param \Zend\View\ViewEvent $e