raykolbe / DOMPDFModule

A Zend Framework module for Dompdf
MIT License
61 stars 62 forks source link

Saving the PDF #9

Closed manuakasam closed 7 years ago

manuakasam commented 11 years ago

Hey Ray,

is there a way to save the generated PDF-File? I am talking about saving it on server-side to not re-render already generated PDF Files that have not been changed (or for versioning control as an example).

I assume i have to attach a listener to the renderer.post event. Have you ever done this? I assume this would be a highly requested feature for people working with the Module.

IF you have done this it would be awesome if you could provide the code for such a thing. I'll be trying to figure it out for myself though ;-)

raykolbe commented 11 years ago

You could use DOMPDF directly by grabbing an instance of it from ServiceLocator.

$dompdf = $serviceManager->get('DOMPDF');
$dompdf->load_html($html);
file_put_contents('someFileOfMine.pdf', $dompdf->render());

This is untested but I believe it should work.

Please note that when you call for DOMPDF from the service locator, you are getting a new instance each time.

Also, using DOMPDF directly like this, you lose rendering support. Perhaps another service should be included in the module that is responsible for template rendering. I have to think about this some more. If you have suggestions let me know ;-)

Leaving this issue open right now for discussion.

cellulosa commented 11 years ago

I managed to stream it as email attachment by doing so:

// generate PDF $pdf = new PdfModel(); $pdf->setOption('filename', 'user_details-' . date("Y_m_d")); $pdf->setOption('paperSize', 'a4'); $pdf->setVariables(array( 'User' => $User, ));

// Render PDF
$pdfView = new ViewModel($pdf);
$pdfView->setTerminal(true)
    ->setTemplate('Application/index/pdf')
    ->setVariables(array(
        'User' => $User,
    ));

$html = $this->getServiceLocator()->get('viewpdfrenderer')->getHtmlRenderer()->render($pdfView);
$eng = $this->getServiceLocator()->get('viewpdfrenderer')->getEngine();

$eng->load_html($html);
$eng->render();
$pdfCode = $eng->output();

neilesh commented 10 years ago

I am new to DOMPDF and confused about its use. please guide me how to use this in ZF2. where I should place this folder in my project and how to install it

vaibhavmalushte commented 10 years ago

Hi, I was trying to use bellow code $sm = $this->getServiceLocator(); $dompdf = $sm->get('DOMPDF'); $homepage = file_get_contents('http://www.gmail.com/'); $dompdf->load_html($homepage); file_put_contents('someFileOfMine.pdf', $dompdf->render()); and got this error :( Call to a member function get_current_line_box() on a non-object in E:\websites\sticky_notes\vendor\dompdf\dompdf\include\absolute_positioner.cls.php on line 92

Please advice. Thank you, Vaibhav

raykolbe commented 7 years ago

Hi all,

As you've noticed DOMPDFModule hasn't received the time and attention it deserves. I understand how frustrating this is and I'm sorry you've had to deal with this frustration 😢

I'm currently taking steps to stabilize DOMPDFModule which includes code updates as well as creating a backlog that will ensure its continued success.

You can follow project Phoneix to see what immediate work is being prioritized.

Thank you for your understanding and patience.