Using HTML2FPDF (an extension of FPDF) to output a pdf - this is working fine. a PDF is opened in the browser with the uri still showing the php file that created it.

I am trying to take the output of that and save it as a pdf file on the server.

The Pdf file is being created, but it's empty.

Where am I going wrong here?

if ($optionSave == "new" || !isset($optionSave) || trim($optionSave) == ""){
        $fileName = "proposal_" . $id . "_" . date("U") . ".pdf";
}
else {
        $fileName = $dbp->published_file_name;
}

// PDF generation actions
require('/path/to/FPDF/html2fpdf.php');
//Initialize class
//define RELATIVE_PATH,FPDF_FONTPATH if needed
$pdf=new HTML2FPDF();
$pdf->AddPage();
$pdf->WriteHTML($dbp->content);

$handle = file_exists('/path/removed/'.$fileName);
if (!$handle){
        $f = fopen('/path/removed/'.$fileName,'x+');
}else{
        echo $fileName;
}
if(!$f) $this->Error('Unable to create output file: '.$fileName);
fwrite ($f,$pdf->Output());
fclose($f);

    I just got FPDF myself. here's a semi-smart question, have you tried testing with dummy text? like this..

    fwrite ($f,'dummy text here..');
    

    If it's there, the problem is $pdf->Output() and you need to check the docs. If the text is NOT there, then it's a problem with $pdf->Output();

    Also I don't know if you're going to wind up with http headers that way so a word of caution there.

    also see here:
    http://www.relatebase.com/devteam/fpdf1.53/doc/output.htm

    Samuel

      13 days later

      simple solution - I should have RTFM

      $content = "This is the PDF content";
      // PDF generation actions
      require('/path/to/file/FPDF/html2fpdf.php');
      //Initialize class
      //define RELATIVE_PATH,FPDF_FONTPATH if needed
      $pdf=new HTML2FPDF();
      $pdf->AddPage();
      $pdf->WriteHTML($content);
      
      // output to browser would come from $_GET - only used to print current proposal
      if (isset($outputToBrowser) && $outputToBrowser == "true"){
              // this outputs pdf directly to the browser
      	$pdf->Output();
      }else {
               // this ouputs the specified file
      	$pdf->Output('/path/to/whatever/file.pdf');
      }
      
        Write a Reply...