Jump to content

Creating PDF with .php using FPDF


Melissafleet

Recommended Posts

I have installed the FPDF library, and inserted this in the page:

 

<?php

require(TEMPLATEPATH . '/fpdf.php');




$pdf = new FPDF('P','mm','A4');


$pdf->AddPage();


$pdf->SetFont('Arial','B',16);


$pdf->Cell(0,10,'PHP - The Good Parts!');


$pdf->Output();
?>

 

It starts creating the pdf, but then an error pops up saying "file does not begin with '%PDF' ?

What could be causing this error?

Link to comment
https://forums.phpfreaks.com/topic/277331-creating-pdf-with-php-using-fpdf/
Share on other sites

Thank you.  I have removed the spaces (line spaces) in between but am still receiving the error?
 

 

<?php
require(TEMPLATEPATH . '/fpdf.php');
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'PHP - The Good Parts!');
$pdf->Output();
?>

 

 
 
Thank you

With addition of 1 line if worked fine for me

<?php
define('TEMPLATEPATH','c:/php/fpdf'); // <--- added this
require(TEMPLATEPATH . '/fpdf.php');
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'PHP - The Good Parts!');
$pdf->Output();
?>

How do you define TEMPLATEPATH?

I am using Wordpress, so I thought that it would find the location of FPDF automatically using TEMPLATEPATH... I assume that is incorrect?

Should I replace your path (c:/php).. etc with the direct path to that file in my cPanel?

 

 

Thank you so much for your help

With addition of 1 line if worked fine for me

<?php
define('TEMPLATEPATH','c:/php/fpdf'); // <--- added this
require(TEMPLATEPATH . '/fpdf.php');
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'PHP - The Good Parts!');
$pdf->Output();
?>

How do you define TEMPLATEPATH?

 

 

The code I posted in reply 4 was in a file on its own. You haven't said if yours is.

 

It worked fine - see attached

 

 

Hi Barand.  Yes it is in a file of it's own.  I edited the path a bit, as I noticed that my folder was named differently to yours, and now it looks as if it is starting to create the document, but then It says " Failed to load PDF" document?

 

Thank you for your reply :)

<?php
define('TEMPLATEPATH','c:/fpdf17'); // <--- added this
require(TEMPLATEPATH . '/fpdf.php');
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'PHP - The Good Parts!');
$pdf->Output();
?>
  • 3 months later...
The following  method shows how to create PDF document .You can try again:
public static void SaveDocumentFile(REDocument document, string filePath);
public static void SaveDocumentFile(BaseImage image, string filePath, BaseEncoder enc);
public static void SaveDocumentFile(List<BaseImage> images, string filePath, BaseEncoder enc);
public static void SaveDocumentFile(REDocument document, string filePath, BaseEncoder enc);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.