1. What's exactly the license of FPDF? Are there any usage restrictions?
FPDF is Freeware (it is stated at the beginning of the source file). There is no usage restriction. You may embed it freely in your application (commercial or not), with or without modification. You may redistribute it, too.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 behaviour is a bug of IE. 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.<INPUT TYPE="HIDDEN" NAME="ext" VALUE=".pdf"> |
//Determine a temporary file name in the current directory $file=basename(tempnam(getcwd(),'tmp')); //Save PDF to file $pdf->Output($file); //JavaScript redirection echo "<HTML><SCRIPT>document.location='getpdf.php?f=$file';</SCRIPT></HTML>"; |
<?php $f=$HTTP_GET_VARS['f']; //Check file (don't skip it!) if(substr($f,0,3)!='tmp' or strpos($f,'/') or strpos($f,'\\')) die('Incorrect file name'); if(!file_exists($f)) die('File does not exist'); //Handle special IE request if needed if($HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') { Header('Content-Type: application/pdf'); exit; } //Output PDF Header('Content-Type: application/pdf'); Header('Content-Length: '.filesize($f)); readfile($f); //Remove file unlink($f); exit; ?> |
//Determine a temporary file name in the current directory $file=basename(tempnam(getcwd(),'tmp')); rename($file,$file.'.pdf'); $file.='.pdf'; //Save PDF to file $pdf->Output($file); //JavaScript redirection echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>"; |
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 send parameters using the POST method and the values don't appear in the PDF.
It's a problem affecting some versions of IE (especially the first 5.5). See the previous question for the ways to work around it.5. When I use a PHP session, IE doesn't display my PDF any more but asks me to download it.
It's a problem affecting some versions of IE. To work around it, add the following line before session_start():session_cache_limiter('private'); |
6. When I'm on SSL, IE can't open the PDF.
The problem may be fixed by adding this line:Header('Pragma: public'); |
7. When I execute a script I get the message "FPDF error: Don't alter the locale before including class file".
When the decimal separator is configured as a comma before including a file, there is a bug in some PHP versions and decimal numbers get truncated. Therefore you shouldn't make a call to setlocale() before including the class. On Unix, you shouldn't set the LC_ALL environment variable neither, for it is equivalent to a setlocale() call.8. I try to put a PNG and Acrobat says "There was an error processing a page. A drawing error occurred".
Acrobat 5 has a bug and is unable to display transparent monochrome images (i.e. with 1 bit per pixel). Remove transparency or save your image in 16 colors (4 bits per pixel) or more.9. I encounter the following error when I try to generate a PDF: Warning: Cannot add header information - headers already sent by (output started at script.php:X)
You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return, neither before nor after. The script outputs something at line X.10. I try to display a variable in the Header method but nothing prints.
You have to use the global keyword, for instance:
function Header() { global $title; $this->SetFont('Arial','B',15); $this->Cell(0,10,$title,1,1,'C'); } |
11. 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(); |
12. 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.13. I try to put 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)); |
14. I draw a frame with very precise dimensions, but when printed I notice some differences.
To respect dimensions, you have to uncheck the option "Fit to page" in the print dialog box.15. 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?
All printers have physical margins (different depending on the model), it is therefore impossible to remove them and print on the totality of the paper.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?
You can import 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?
No. But some free tools exist to perform this task: