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

Force save file on server #125

Open
prakashsinghgaur opened this issue Feb 17, 2017 · 1 comment
Open

Force save file on server #125

prakashsinghgaur opened this issue Feb 17, 2017 · 1 comment

Comments

@prakashsinghgaur
Copy link

Hi.. there

I want the generated pdf file to be immediately saved in directory on server..

Any possible ways :)

Regards

@prakashsinghgaur
Copy link
Author

prakashsinghgaur commented Jun 17, 2017

for all those struggling with the same issue here is what I have done to achieve this:-
First I created a facade object
$facade = $this->get('ps_pdf.facade');
$response = new Response();

Then I passed all the required variables to twig template:

$this->render('print/printAgreement.pdf.twig', array(
'vision' => $vision));

Then added any necessary stylesheets, generated xml content response, added the response to facade object

$stylesheet = $this->renderView('PsPdfBundle:Example:pdfStylesheet.xml.twig', array());
$xml = $response->getContent();
$pdf = $facade->render($xml, $stylesheet);

Instantiated a new file object
$fs = new Filesystem();
Finally, called dumpfile() function of file system object
$filename = 'something';
$fs->dumpFile('folderpath/'.$filename.'.pdf', $pdf);

It will dump/store the generated pdf file to the given path on the server. Given that proper write permission are there on the folder.

Thanks

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

No branches or pull requests

1 participant