1. What's exactly the license of FPDF? Are there any usage restrictions?
FPDF is released under a permissive license: there is no usage restriction. You may embed it freely in your application (commercial or not), with or without modifications.2. When I try to create a PDF, a lot of weird characters show on the screen. Why?
These "weird" characters are in fact the actual content of your PDF. This behavior is a bug of IE6. When it first receives an HTML page, then a PDF from the same URL, it displays it directly without launching Acrobat. This happens frequently during the development stage: on the least script error, an HTML page is sent, and after correction, the PDF arrives.3. I try to generate a PDF and IE displays a blank page. What happens?
First of all, check that you send nothing to the browser after the PDF (not even a space or a carriage return). You can put an exit statement just after the call to the Output() method to be sure. If it still doesn't work, it means you're a victim of the "blank page syndrome". IE used in conjunction with the Acrobat plug-in suffers from many bugs. To avoid these problems in a reliable manner, two main techniques exist://Determine a temporary file name in the current directory
$file = basename(tempnam('.', 'tmp'));
rename($file, $file.'.pdf');
$file .= '.pdf';
//Save PDF to file
$pdf->Output($file, 'F');
//Redirect
header('Location: '.$file);
function CleanFiles($dir)
{
//Delete temporary files
$t = time();
$h = opendir($dir);
while($file=readdir($h))
{
if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')
{
$path = $dir.'/'.$file;
if($t-filemtime($path)>3600)
@unlink($path);
}
}
closedir($h);
}
4. I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.
You have to enclose your string with double quotes, not single ones.5. I try to display a variable in the Header method but nothing prints.
You have to use theglobal
keyword to access global variables, for example:
function Header()
{
global $title;
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, $title, 1, 1, 'C');
}
$title = 'My title';
function Header()
{
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, $this->title, 1, 1, 'C');
}
$pdf->title = 'My title';
6. I defined the Header and Footer methods in my PDF class but nothing appears.
You have to create an object from the PDF class, not FPDF:$pdf = new PDF();
7. Accented characters are replaced by some strange characters like é.
Don't use UTF-8 encoding. Standard FPDF fonts use ISO-8859-1 or Windows-1252. It is possible to perform a conversion to ISO-8859-1 with utf8_decode():$str = utf8_decode($str);
$str = iconv('UTF-8', 'windows-1252', $str);
8. I try to display the Euro symbol but it doesn't work.
The standard fonts have the Euro character at position 128. You can define a constant like this for convenience:define('EURO', chr(128));
9. I get the following error when I try to generate a PDF: Some data has already been output, can't send PDF file
You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return. You may have this other message just before:ob_end_clean();
10. I draw a frame with very precise dimensions, but when printed I notice some differences.
To respect dimensions, select "None" for the Page Scaling setting instead of "Shrink to Printable Area" in the print dialog box.11. I'd like to use the whole surface of the page, but when printed I always have some margins. How can I get rid of them?
Printers have physical margins (different depending on the models); it is therefore impossible to remove them and print on the whole surface of the paper.12. How can I put a background in my PDF?
For a picture, call Image() in the Header() method, before any other output. To set a background color, use Rect().13. How can I set a specific header or footer on the first page?
Simply test the page number:function Header()
{
if($this->PageNo()==1)
{
//First page
...
}
else
{
//Other pages
...
}
}
14. I'd like to use extensions provided by different scripts. How can I combine them?
Use an inheritance chain. If you have two classes, say A in a.php:require('fpdf.php');
class A extends FPDF
{
...
}
require('fpdf.php');
class B extends FPDF
{
...
}
require('a.php');
class B extends A
{
...
}
require('b.php');
class PDF extends B
{
...
}
$pdf = new PDF();
15. How can I send the PDF by email?
As any other file, but an easy way is to use PHPMailer and its in-memory attachment:$mail = new PHPMailer();
...
$doc = $pdf->Output('', 'S');
$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
$mail->Send();
16. What's the limit of the file sizes I can generate with FPDF?
There is no particular limit. There are some constraints, however:17. Can I modify a PDF with FPDF?
It is possible to import pages from an existing PDF document thanks to the FPDI extension:18. I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?
No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from a PDF. It is provided with the Xpdf package:19. Can I convert an HTML page to PDF with FPDF?
Not real-world pages. But a GPL C utility does exist, htmldoc, which allows to do it and gives good results:20. Can I concatenate PDF files with FPDF?
Not directly, but it is possible to use FPDI to perform this task. Some free command-line tools also exist: