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?

Edited by Melissafleet
Link to comment
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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();
?>
Edited by Melissafleet
Link to comment
Share on other sites

  • 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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.