0

I have a PHP page with the following code.

<?php
$filepath = '../../../user_uploads/'.$_path['uploads']
            .'prtl_icons/mod_icons_1438512347.jpg';
  require('../../../fpdf/fpdf.php');
 class PDF extends FPDF
 {
     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');
   }
 }
$pdf = new PDF('P','mm','A4');
$pdf->Image('http://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World',60,30,90,0,'PNG');
//$pdf->Image($filepath);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',11);
$pdf->Cell(40,10,'Family: ['.$_SESSION['UserID'].'] - '.$_SESSION['FirstName']);
$pdf->Output();
 ?>

When I run the page,I am getting the following error.

Fatal error: Uncaught exception 'Exception' with message 'FPDF error: No page has been added yet' in /var/www/vhosts/portal.dev/fpdf/fpdf.php:271 
Stack trace: #0 /var/www/vhosts/portal.dev/fpdf/fpdf.php(1450): FPDF->Error('No page has bee...') #1 /var/www/vhosts/portal.dev/fpdf/fpdf.php
(924): FPDF->_out('q 255.12 0 0 10...') #2 /var/www/vhosts/portal.dev/module/parents/calendar/pdf_loader.php(25): 
FPDF->Image('http://chart.go...', 60, 30, 90, 0, 'PNG') #3 {main} 
 thrown in /var/www/vhosts/portal.dev/fpdf/fpdf.php on line 271.

When i either used $pdf->Image($filepath),also same error is showing.When i remove the image part,the pdf is loading properly.

Techy
  • 2,626
  • 7
  • 41
  • 88
  • the issue is related to images..I am not sure why this happens – Techy Jun 11 '17 at 13:09
  • You have `$pdf->Image('...',60,30,90,0,'PNG');` You give `HEIGHT=0`. Are you sure? –  Jun 11 '17 at 13:16
  • Also, which version of FPDF are you using? –  Jun 11 '17 at 13:18
  • @aendeerei 1.81 version – Techy Jun 11 '17 at 13:20
  • I have pasted the$pdf-> image() after the setFont() and is working – Techy Jun 11 '17 at 13:21
  • 1
    Perfect ;-) Otherwise, here is your answer also: `$pdf->AddPage();` and don't output anything before fpdf output! See [THIS](https://stackoverflow.com/questions/9475686/fpdf-error-some-data-has-already-been-output-cant-send-pdf) –  Jun 11 '17 at 13:23

0 Answers0