psliwa / PHPPdf

Pdf and graphic files generator library written in php

Home Page:http://ohey.pl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Force save file on server

prakashsinghgaur opened this issue · comments

Hi.. there

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

Any possible ways :)

Regards

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