0

So I have run into a bit of a problem with fpdf. I am generating a report successfully, except when I try to add a header/footer, it just displays a blank page. Not even the Pdf viewer. I have just copied the example from the tutorial on the fpdf website, and I have used $pdf-> new PDF instead of $pdf-> new FPDF, as suggested under every similar question here. But the problem persists. There seems to be another issue, that is the I also get a blank page unless I comment out the require 'fpdf/fpdf.php';. Only if it is commented out, does the pdf show. Here's my code :

//require '/usr/share/php/fpdf/fpdf.php';
/////////ADD HEADER, FOOTER AND NEW PAGE/ MARGIN SETTING////////////


class PDF extends FPDF
{

    // Page header

    function Header()
{
    // Logo
    $this->Image("../tmp/headers/header2.",0,0,210);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(30,10,'Title',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

// Instanciation of inherited class
//$pdf = new PDF();
//$pdf->AliasNbPages();
//$pdf->AddPage();
//$pdf->Header();
//$pdf->SetFont('Times','',12);
//for($i=1;$i<=40;$i++)
  //  $pdf->Cell(0,10,'Printing line number '.$i,0,1);
//$pdf->Output();


//--------------------  Start of Title Page  --------------------//

//start pdf file, add page, set font
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddGBFont();
$pdf->AddBig5Font();
$pdf->AddPage();
/////rest of the report /////
$pdf->Output();
tehnininess
  • 21
  • 1
  • 9
  • Please edit your question to include code that has even a slight possibility of actually working. At the moment most of the code is commented out. Also, it's best to ask a single question, not two separate ones. – KIKO Software Sep 30 '22 at 06:40
  • Apologies. Edited. – tehnininess Sep 30 '22 at 06:59
  • 1
    When PHP code displays a blank page it is most likely because it cannot execute enough code to generate output. Usually an error is the problem. You can find error messages in [the error log](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php-5-apache-fastcgi-and-cpanel), or you can [let PHP display errors](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). The latter will not work for syntax errors. I do not _see_ any syntax errors in your code. – KIKO Software Sep 30 '22 at 07:03
  • `AddGBFont()` and `AddBig5Font()` are not part of FPDF. – Olivier Sep 30 '22 at 19:07
  • @Olivier That doesn't seem to be the problem as though – tehnininess Oct 04 '22 at 05:17

0 Answers0