FAQ

1. What is exactly the FPDF license? Are there any usage restrictions?
2. When I try to create a PDF, a lot of weird characters show on the screen. Why?
3. I try to generate a PDF and IE displays a blank page. What happens?
4. I send parameters using the POST method and the values don't appear in the PDF.
5. I try to display a PDF and Acrobat says "There was an error processing a page. Too few operands." followed by "An unrecognized token '2,88' was found.".
6. I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.
7. I try to put the euro symbol but it doesn't work.
8. I draw a frame with very precise dimensions, but when printed I notice some differences.
9. 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?
10. What's the limit of the file sizes I can generate with FPDF?
11. Can I modify a PDF with FPDF?
12. I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?
13. Can I convert an HTML page to PDF with FPDF?
14. Can I concatenate PDF files with FPDF?
15. How can I activate the protections on a PDF? I'd like to prevent people from copying the text or modifying the document.
16. I'd like to add new fonts. How can I do it? How can I create files similar to those in the font directory?
17. How can I use a charset other than the default one?


1. What is exactly the FPDF license? Are there any usage restrictions?

FPDF is Freeware (it's stated at the beginning of the source file). There is no usage restrictions.

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.
To solve the problem, simply quit and restart IE. You can also go to another URL and come back.
To avoid this kind of inconvenience during the development, you can generate the PDF directly to a file and open it through the explorer.

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 numerous bugs, in all versions. You should test your application with as many IE versions as possible (at least if you're on the Internet). The problem occurs mostly with the POST method, so it is advised to avoid it (all the more that it causes other problems, see the next question). The GET works better but may fail when the URL becomes too long: don't use a query string with more than 45 characters. However, a tip exists to exceed this limit: end the URL with .pdf, which deceives IE. If you use a formular, you can add a hidden field at the last position:

<INPUT TYPE="HIDDEN" NAME="ext" VALUE=".pdf">

The usage of PHP sessions also often causes trouble (avoid using cache-related HTTP headers).

If you can't or don't want to use the GET method, or still experience trouble, or need a PHP session to generate the document, two solutions exist to work around the problem:

- Disable the plug-in and use Acrobat as a helper application. To do this, launch Acrobat; in the File menu, Preferences, General, uncheck the option "Web Browser Integration" (for Acrobat 5: Edit, Preferences, Options, "Display PDF in Browser"). Then, the next time you load a PDF in IE, it displays the dialog box "Open it" or "Save it to disk". Uncheck the option "Always ask before opening this type of file" and choose Open. From now on, PDF files will open automatically in an external Acrobat window.
The drawback of the method is that you need to alter the client configuration, which you can do in an intranet environment but not for the Internet.

- Use a redirection technique. It consists in generating the PDF in a temporary file on the server and redirect the client on it (by using JavaScript, not the Location HTTP header which also causes trouble). For instance, at the end of the script, you can put the following:

//Determine a temporary file name in the current directory
$file=basename(tempnam(getcwd(),'pdf'));
//Save the PDF in the file
$pdf->Output($file);
//JavaScript redirection
echo "<HTML><SCRIPT>document.location='getpdf.php?f=$file';</SCRIPT></HTML>";

Then create the getpdf.php file with this:

<?php
$f=$HTTP_GET_VARS['f'];
//Check file (don't skip it!)
if(substr($f,0,3)!='pdf' or strpos($f,'.php') 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_ENV_VARS['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;
?>

This method seems to work in all cases. A variant consists in redirecting directly to the temporary file, but you will have to manage cleaning somewhere in order to delete the files.
Remark: it is necessary to open the PDF in a new window, as you can't go backwards due to the redirection.

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 means to work around it.

5. I try to display a PDF and Acrobat says "There was an error processing a page. Too few operands." followed by "An unrecognized token '2,88' was found.".

This is a locale-related problem. The decimal separator is configured as a comma whereas the period is necessary to produce valid PDF files. To get the correct setting, add the following line:

setlocale('LC_NUMERIC','en');

6. 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 by double quotes, not single ones.

7. I try to put the euro symbol but it doesn't work.

Use chr(128). You can define a constant like this:

define('EURO',chr(128));

8. 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.

9. 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.

10. What's the limit of the file sizes I can generate with FPDF?

There is no particular limit. There are some constraints however:

- The maximum memory size allocated to PHP scripts defaults to 8MB. For very big documents, especially with images, this limit may be reached (the file being built into memory). The parameter is configured in the php.ini file.

- The maximum execution time allocated defaults to 30 seconds. This limit can of course be easily reached. It is configured in php.ini and may be altered dynamically with set_time_limit().

- Browsers generally have a 5 minute time-out. If you send the PDF directly to the browser and reach the limit, it will be lost. It is therefore advised for very big documents to generate them in a file, and to send some data to the browser from time to time (for instance page 1, page 2... with flush() to force the output). When the document is finished, you can send a redirection on it with JavaScript or create a link.
Remark: even when the browser goes in time-out, the script generally continues to run on the server.

11. Can I modify a PDF with FPDF?

No. There will be (I hope) a version in the future which will allow to import the content of a PDF and add elements to it.

12. I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?

No. But a C utility does exist, pdftotext, which is able to extract the textual content from a PDF. It is provided within the Xpdf package.

http://www.foolabs.com/xpdf/

13. Can I convert an HTML page to PDF with FPDF?

No. But a C utility does exist, htmldoc, which allows to do it and gives good results.

http://www.easysw.com/htmldoc/

14. Can I concatenate PDF files with FPDF?

No.

15. How can I activate the protections on a PDF? I'd like to prevent people from copying the text or modifying the document.

You can't for the moment. Protecting a PDF requires to crypt it, and the algorithm used (RC4) is theoretically not free (even if this issue seems to be a little fuzzy and the algorithm might be tolerated for a non-commercial usage).

16. I'd like to add new fonts. How can I do it? How can I create files similar to those in the font directory?

You can't for the moment use fonts other than the standard ones. Generating a metric file is not sufficient to add a font, it's more complicated than that. The feature will be added in a future version.

17. How can I use a charset other than the default one?

You currently can't. I'll add the feature in future versions. I hope to be able to support the main ones (Central Europe, Cyrillic, Chinese, Japanese, Korean).