Download or Save FPDF output in Specific directory


We can download or save fpdf outpur using output method in fpdf.

Syntax
<?php
  $pdf->Output('F', $filename, true);
?>
  • I : default. send the file to the browser.
  • D : download with given file name.
  • F : save to a local with given file name.
  • S : return the document as a string.

  • false : name is encoded in ISO-8859-1
  • true : name is encoded in UTF-8

The following example to download fpdf output with given name.

 
<?php 
  require('fpdf/fpdf.php');
  
  $filename="sample.pdf";
  
  $pdf=new FPDF("P","mm","A4");
  $pdf->AddPage();
  $pdf->SetFont('Arial','',16);
  $pdf->Cell(0,10,"This sample text",0,1,'C');
  $pdf->Output('D', $filename, true);	
?>

The following example to save fpdf output in files folder with given name.

 
<?php 
  require('fpdf/fpdf.php');
  
  //In which folder you want to save
  $dir="files/";
  
  $filename="sample.pdf";
  
  $pdf=new FPDF("P","mm","A4");
  $pdf->AddPage();
  $pdf->SetFont('Arial','',16);
  $pdf->Cell(0,10,"This sample text",0,1,'C');
  $pdf->Output('F', $dir.$filename, true);
?>