blob: dd263ec0489bffb0c89c2b1538510d6f6d040d06 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>FAQ</title>
6<link type="text/css" rel="stylesheet" href="fpdf.css">
7<style type="text/css">
8ul {list-style-type:none; margin:0; padding:0}
9ul#answers li {margin-top:1.8em}
10.question {font-weight:bold; color:#900000}
11</style>
12</head>
13<body>
14<h1>FAQ</h1>
15<ul>
16<li><b>1.</b> <a href='#q1'>What's exactly the license of FPDF? Are there any usage restrictions?</a></li>
17<li><b>2.</b> <a href='#q2'>I get the following error when I try to generate a PDF: Some data has already been output, can't send PDF file</a></li>
18<li><b>3.</b> <a href='#q3'>Accented letters are replaced by some strange characters like é.</a></li>
19<li><b>4.</b> <a href='#q4'>I try to display the Euro symbol but it doesn't work.</a></li>
20<li><b>5.</b> <a href='#q5'>I try to display a variable in the Header method but nothing prints.</a></li>
21<li><b>6.</b> <a href='#q6'>I have defined the Header and Footer methods in my PDF class but nothing shows.</a></li>
22<li><b>7.</b> <a href='#q7'>I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.</a></li>
23<li><b>8.</b> <a href='#q8'>I use jQuery to generate the PDF but it doesn't show.</a></li>
24<li><b>9.</b> <a href='#q9'>I draw a frame with very precise dimensions, but when printed I notice some differences.</a></li>
25<li><b>10.</b> <a href='#q10'>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?</a></li>
26<li><b>11.</b> <a href='#q11'>How can I put a background in my PDF?</a></li>
27<li><b>12.</b> <a href='#q12'>How can I set a specific header or footer on the first page?</a></li>
28<li><b>13.</b> <a href='#q13'>I'd like to use extensions provided by different scripts. How can I combine them?</a></li>
29<li><b>14.</b> <a href='#q14'>How can I open the PDF in a new tab?</a></li>
30<li><b>15.</b> <a href='#q15'>How can I send the PDF by email?</a></li>
31<li><b>16.</b> <a href='#q16'>What's the limit of the file sizes I can generate with FPDF?</a></li>
32<li><b>17.</b> <a href='#q17'>Can I modify a PDF with FPDF?</a></li>
33<li><b>18.</b> <a href='#q18'>I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?</a></li>
34<li><b>19.</b> <a href='#q19'>Can I convert an HTML page to PDF with FPDF?</a></li>
35<li><b>20.</b> <a href='#q20'>Can I concatenate PDF files with FPDF?</a></li>
36</ul>
37
38<ul id='answers'>
39<li id='q1'>
40<p><b>1.</b> <span class='question'>What's exactly the license of FPDF? Are there any usage restrictions?</span></p>
41FPDF is released under a permissive license: there is no usage restriction. You may embed it
42freely in your application (commercial or not), with or without modifications.
43</li>
44
45<li id='q2'>
46<p><b>2.</b> <span class='question'>I get the following error when I try to generate a PDF: Some data has already been output, can't send PDF file</span></p>
47You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return. A common
48case is having extra blank at the end of an included script file.<br>
49<br>
50The message may be followed by this indication:<br>
51<br>
52(output started at script.php:X)<br>
53<br>
54which gives you exactly the script and line number responsible for the output. If you don't see it,
55try adding this line at the very beginning of your script:
56<div class="doc-source">
57<pre><code>ob_end_clean();</code></pre>
58</div>
59</li>
60
61<li id='q3'>
62<p><b>3.</b> <span class='question'>Accented letters are replaced by some strange characters like é.</span></p>
63Don't use UTF-8 with the standard fonts; they expect text encoded in windows-1252.
64You can perform a conversion with iconv:
65<div class="doc-source">
66<pre><code>$str = iconv('UTF-8', 'windows-1252', $str);</code></pre>
67</div>
68Or with mbstring:
69<div class="doc-source">
70<pre><code>$str = mb_convert_encoding($str, 'windows-1252', 'UTF-8');</code></pre>
71</div>
72In case you need characters outside windows-1252, take a look at tutorial #7 or
73<a href="http://www.fpdf.org/?go=script&amp;id=92" target="_blank">tFPDF</a>.
74</li>
75
76<li id='q4'>
77<p><b>4.</b> <span class='question'>I try to display the Euro symbol but it doesn't work.</span></p>
78The standard fonts have the Euro character at position 128. You can define a constant like this
79for convenience:
80<div class="doc-source">
81<pre><code>define('EURO', chr(128));</code></pre>
82</div>
83</li>
84
85<li id='q5'>
86<p><b>5.</b> <span class='question'>I try to display a variable in the Header method but nothing prints.</span></p>
87You have to use the <code>global</code> keyword to access global variables, for example:
88<div class="doc-source">
89<pre><code>function Header()
90{
91 global $title;
92
93 $this-&gt;SetFont('Arial', 'B', 15);
94 $this-&gt;Cell(0, 10, $title, 1, 1, 'C');
95}
96
97$title = 'My title';</code></pre>
98</div>
99Alternatively, you can use an object property:
100<div class="doc-source">
101<pre><code>function Header()
102{
103 $this-&gt;SetFont('Arial', 'B', 15);
104 $this-&gt;Cell(0, 10, $this-&gt;title, 1, 1, 'C');
105}
106
107$pdf-&gt;title = 'My title';</code></pre>
108</div>
109</li>
110
111<li id='q6'>
112<p><b>6.</b> <span class='question'>I have defined the Header and Footer methods in my PDF class but nothing shows.</span></p>
113You have to create an object from the PDF class, not FPDF:
114<div class="doc-source">
115<pre><code>$pdf = new PDF();</code></pre>
116</div>
117</li>
118
119<li id='q7'>
120<p><b>7.</b> <span class='question'>I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.</span></p>
121You have to enclose your string with double quotes, not single ones.
122</li>
123
124<li id='q8'>
125<p><b>8.</b> <span class='question'>I use jQuery to generate the PDF but it doesn't show.</span></p>
126Don't use an AJAX request to retrieve the PDF.
127</li>
128
129<li id='q9'>
130<p><b>9.</b> <span class='question'>I draw a frame with very precise dimensions, but when printed I notice some differences.</span></p>
131To respect dimensions, select "None" for the Page Scaling setting instead of "Shrink to Printable Area" in the print dialog box.
132</li>
133
134<li id='q10'>
135<p><b>10.</b> <span class='question'>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?</span></p>
136Printers have physical margins (different depending on the models); it is therefore impossible to remove
137them and print on the whole surface of the paper.
138</li>
139
140<li id='q11'>
141<p><b>11.</b> <span class='question'>How can I put a background in my PDF?</span></p>
142For a picture, call Image() in the Header() method, before any other output. To set a background color, use Rect().
143</li>
144
145<li id='q12'>
146<p><b>12.</b> <span class='question'>How can I set a specific header or footer on the first page?</span></p>
147Just test the page number:
148<div class="doc-source">
149<pre><code>function Header()
150{
151 if($this-&gt;PageNo()==1)
152 {
153 //First page
154 ...
155 }
156 else
157 {
158 //Other pages
159 ...
160 }
161}</code></pre>
162</div>
163</li>
164
165<li id='q13'>
166<p><b>13.</b> <span class='question'>I'd like to use extensions provided by different scripts. How can I combine them?</span></p>
167Use an inheritance chain. If you have two classes, say A in a.php:
168<div class="doc-source">
169<pre><code>require('fpdf.php');
170
171class A extends FPDF
172{
173...
174}</code></pre>
175</div>
176and B in b.php:
177<div class="doc-source">
178<pre><code>require('fpdf.php');
179
180class B extends FPDF
181{
182...
183}</code></pre>
184</div>
185then make B extend A:
186<div class="doc-source">
187<pre><code>require('a.php');
188
189class B extends A
190{
191...
192}</code></pre>
193</div>
194and make your own class extend B:
195<div class="doc-source">
196<pre><code>require('b.php');
197
198class PDF extends B
199{
200...
201}
202
203$pdf = new PDF();</code></pre>
204</div>
205</li>
206
207<li id='q14'>
208<p><b>14.</b> <span class='question'>How can I open the PDF in a new tab?</span></p>
209Just do the same as you would for an HTML page or anything else: add a target="_blank" to your link or form.
210</li>
211
212<li id='q15'>
213<p><b>15.</b> <span class='question'>How can I send the PDF by email?</span></p>
214As for any other file, but an easy way is to use <a href="https://github.com/PHPMailer/PHPMailer" target="_blank">PHPMailer</a> and
215its in-memory attachment:
216<div class="doc-source">
217<pre><code>$mail = new PHPMailer();
218...
219$doc = $pdf-&gt;Output('S');
220$mail-&gt;AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
221$mail-&gt;Send();</code></pre>
222</div>
223</li>
224
225<li id='q16'>
226<p><b>16.</b> <span class='question'>What's the limit of the file sizes I can generate with FPDF?</span></p>
227There is no particular limit. There are some constraints, however:
228<br>
229<br>
230- There is usually a maximum memory size allocated to PHP scripts. For very big documents,
231especially with images, the limit may be reached (the file being built in memory). The
232parameter is configured in the php.ini file.
233<br>
234<br>
235- The maximum execution time allocated to scripts defaults to 30 seconds. This limit can of course
236be easily reached. It is configured in php.ini and may be altered dynamically with set_time_limit().
237<br>
238<br>
239You can work around the memory limit with <a href="http://www.fpdf.org/?go=script&amp;id=76" target="_blank">this script</a>.
240</li>
241
242<li id='q17'>
243<p><b>17.</b> <span class='question'>Can I modify a PDF with FPDF?</span></p>
244It's possible to import pages from an existing PDF document thanks to the
245<a href="https://www.setasign.com/products/fpdi/about/" target="_blank">FPDI</a> extension.
246Then you can add some content to them.
247</li>
248
249<li id='q18'>
250<p><b>18.</b> <span class='question'>I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?</span></p>
251No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from a PDF.
252It's provided with the <a href="https://www.xpdfreader.com" target="_blank">Xpdf</a> package.
253</li>
254
255<li id='q19'>
256<p><b>19.</b> <span class='question'>Can I convert an HTML page to PDF with FPDF?</span></p>
257Not real-world pages. But a GPL C utility does exist, <a href="https://www.msweet.org/htmldoc/" target="_blank">HTMLDOC</a>,
258which allows to do it and gives good results.
259</li>
260
261<li id='q20'>
262<p><b>20.</b> <span class='question'>Can I concatenate PDF files with FPDF?</span></p>
263Not directly, but it's possible to use <a href="https://www.setasign.com/products/fpdi/demos/concatenate-fake/" target="_blank">FPDI</a>
264to perform that task. Some free command-line tools also exist:
265<a href="https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/" target="_blank">pdftk</a> and
266<a href="http://thierry.schmit.free.fr/spip/spip.php?article15" target="_blank">mbtPdfAsm</a>.
267</li>
268</ul>
269</body>
270</html>