0% found this document useful (0 votes)
7 views

FAQ11

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

FAQ11

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

FAQ

• 1. What's exactly the license of FPDF? Are there any usage restrictions?
• 2. I get the following error when I try to generate a PDF: Some data has already
been output, can't send PDF file
• 3. Accented letters are replaced by some strange characters like é.
• 4. I try to display the Euro symbol but it doesn't work.
• 5. I try to display a variable in the Header method but nothing prints.
• 6. I have defined the Header and Footer methods in my PDF class but nothing
shows.
• 7. I can't make line breaks work. I put \n in the string printed by MultiCell but it
doesn't work.
• 8. I use jQuery to generate the PDF but it doesn't show.
• 9. I draw a frame with very precise dimensions, but when printed I notice some
differences.
• 10. 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?
• 11. How can I put a background in my PDF?
• 12. How can I set a specific header or footer on the first page?
• 13. I'd like to use extensions provided by different scripts. How can I combine
them?
• 14. How can I open the PDF in a new tab?
• 15. How can I send the PDF by email?
• 16. What's the limit of the file sizes I can generate with FPDF?
• 17. Can I modify a PDF with FPDF?
• 18. I'd like to make a search engine in PHP and index PDF files. Can I do it with
FPDF?
• 19. Can I convert an HTML page to PDF with FPDF?
• 20. Can I concatenate PDF files with FPDF?

• 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. 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. A common case is having extra blank at the end of an included
script file.

The message may be followed by this indication:

(output started at script.php:X)


which gives you exactly the script and line number responsible for the output. If you
don't see it, try adding this line at the very beginning of your script:

ob_end_clean();

• 3. Accented letters are replaced by some strange characters like é.

Don't use UTF-8 with the standard fonts; they expect text encoded in windows-
1252. You can perform a conversion with iconv:

$str = iconv('UTF-8', 'windows-1252', $str);

Or with mbstring:

$str = mb_convert_encoding($str, 'windows-1252', 'UTF-8');

In case you need characters outside windows-1252, take a look at tutorial #7 or


tFPDF.

• 4. 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));

• 5. I try to display a variable in the Header method but nothing prints.

You have to use the global 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';

Alternatively, you can use an object property:

function Header()
{
$this->SetFont('Arial', 'B', 15);
$this->Cell(0, 10, $this->title, 1, 1, 'C');
}
$pdf->title = 'My title';

• 6. I have defined the Header and Footer methods in my PDF class but nothing
shows.

You have to create an object from the PDF class, not FPDF:

$pdf = new PDF();

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

• 8. I use jQuery to generate the PDF but it doesn't show.

Don't use an AJAX request to retrieve the PDF.

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

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

• 11. 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().

• 12. How can I set a specific header or footer on the first page?

Just test the page number:

function Header()
{
if($this->PageNo()==1)
{
//First page
...
}
else
{
//Other pages
...
}
}

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


{
...
}

and B in b.php:

require('fpdf.php');

class B extends FPDF


{
...
}

then make B extend A:

require('a.php');

class B extends A
{
...
}

and make your own class extend B:

require('b.php');

class PDF extends B


{
...
}

$pdf = new PDF();

• 14. How can I open the PDF in a new tab?

Just do the same as you would for an HTML page or anything else: add a
target="_blank" to your link or form.
• 15. How can I send the PDF by email?

As for 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:

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

- The maximum execution time allocated to scripts 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().

You can work around the memory limit with this script.

• 17. Can I modify a PDF with FPDF?

It's possible to import pages from an existing PDF document thanks to the FPDI
extension. Then you can add some content to them.

• 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's 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's possible to use FPDI to perform that task. Some free command-
line tools also exist: pdftk and mbtPdfAsm.

You might also like