Jump to content

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
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();
?>
Edited by Melissafleet
  • 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);
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.