dave
dave

Reputation: 15489

php how to save an fpdi object as a pdf file

I'm using fpdi for creating/editing my pdfs, and was wondering how to save the output(essentially "save as" a pdf file) to the local harddrive? Example:

$pdf = new FPDI();
$pdf->setSourceFile("test.pdf");
$page= $pdf->importPage(1);
$pdf->addPage();
$pdf->useTemplate($page);

$pdf->Output();  // So instead of outputting to browser, how to save file as a pdf?

Basically instead of outputting the fpdi object, how do i save it as a pdf file?

Upvotes: 2

Views: 14372

Answers (3)

David Duval
David Duval

Reputation: 36

Using FPDF:

$pdfData = $pdf->Output('nameOfFile.php','F') //Save as pdf file (Make sure you have permisions)
$pdfData = $pdf->Output('nameOfFile.php','S') //Return the document as string

Upvotes: 2

Ray O'Donnell
Ray O'Donnell

Reputation: 781

FPDI is a extension for FPDF, so you can get the PDF data as a string:

$pdfData = $pdf->Output('', 'S')

You can then save this to disk in any way you want.

Upvotes: 0

René Höhle
René Höhle

Reputation: 27325

You can define an output file in the output function.

$filename="/home/user/public_html/test.pdf";
$pdf->Output($filename,'F');

Upvotes: 10

Related Questions