Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate pdf files on server side #27

Open
BigAndini opened this issue Feb 9, 2015 · 4 comments
Open

How to generate pdf files on server side #27

BigAndini opened this issue Feb 9, 2015 · 4 comments

Comments

@BigAndini
Copy link

Hi,

maybe somebody besides me is searching for a solution on how to generate pdf files on server side. Here is a small example that works for me. Maybe it finds its way to the readme. :)

$pdfView = new ViewModel();
# When the action can be found at:
# MyModule/MyController/mypdf
# the path to the according template would be:
# my-module/my-controller/mypdf
$pdfView->setTemplate('my-module/my-controller/mypdf');
$pdfView->setVariables(array(
    'somevar' => $somevar,
));
$pdfRenderer = $this->getServiceLocator()->get('ViewPdfRenderer');
$html = $pdfRenderer->getHtmlRenderer()->render($pdfView);
$pdfEngine = $pdfRenderer->getEngine();

$pdfEngine->load_html($html);
$pdfEngine->render();
$pdfContent = $pdfEngine->output();

# make sure to create public/pdf before
file_put_contents(getcwd().'/public/pdf/mypdf.pdf', $pdfContent);

greetings
Andi

P.S.: This is more an enhancement for the readme than a real issue, but I don't know how to change the issue type on github, yet.

@mlumbroso
Copy link

Thanks for this fully working example. This should definitely make its way to the readme :-)

Have you found a way to set option using this method? I wasn't able to change paperSize e.g. using the setOption technique.

@BigAndini
Copy link
Author

Yes, anyhow we managed it to generate A4 instead of Letter PDFs. This is our ETicketService:

https://github.com/inbaz/ers/blob/master/module/PreReg/src/PreReg/Service/ETicketService.php

We set the option directly inside of the pdfEngine. There are still some errors in this code and some duplicate statements. The interesting part starts at line 348 where $paperSize is used again.

Does this help?

@mlumbroso
Copy link

Yes this is great! Thanks for your extremely quick reply, it definitely helps :-) (It's people like you who make Github that amazing!)

@raykolbe
Copy link
Owner

Hi @inbaz and @mlumbroso,

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants