source: trunk/client/inc/hpdf/_fpdf/FAQ.htm@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 13.7 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
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'>When I try to create a PDF, a lot of weird characters show on the screen. Why?</a></li>
18<li><b>3.</b> <a href='#q3'>I try to generate a PDF and IE displays a blank page. What happens?</a></li>
19<li><b>4.</b> <a href='#q4'>I can't make line breaks work. I put \n in the string printed by MultiCell 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 defined the Header and Footer methods in my PDF class but nothing appears.</a></li>
22<li><b>7.</b> <a href='#q7'>Accented characters are replaced by some strange characters like é.</a></li>
23<li><b>8.</b> <a href='#q8'>I try to display the Euro symbol but it doesn't work.</a></li>
24<li><b>9.</b> <a href='#q9'>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>
25<li><b>10.</b> <a href='#q10'>I draw a frame with very precise dimensions, but when printed I notice some differences.</a></li>
26<li><b>11.</b> <a href='#q11'>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>
27<li><b>12.</b> <a href='#q12'>How can I put a background in my PDF?</a></li>
28<li><b>13.</b> <a href='#q13'>How can I set a specific header or footer on the first page?</a></li>
29<li><b>14.</b> <a href='#q14'>I'd like to use extensions provided by different scripts. How can I combine them?</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'>When I try to create a PDF, a lot of weird characters show on the screen. Why?</span></p>
47These "weird" characters are in fact the actual content of your PDF. This behavior is a bug of
48IE6. When it first receives an HTML page, then a PDF from the same URL, it displays it directly
49without launching Acrobat. This happens frequently during the development stage: on the least
50script error, an HTML page is sent, and after correction, the PDF arrives.
51<br>
52To solve the problem, simply quit and restart IE. You can also go to another URL and come
53back.
54<br>
55To avoid this kind of inconvenience during the development, you can generate the PDF directly
56to a file and open it through the explorer.
57</li>
58
59<li id='q3'>
60<p><b>3.</b> <span class='question'>I try to generate a PDF and IE displays a blank page. What happens?</span></p>
61First of all, check that you send nothing to the browser after the PDF (not even a space or a
62carriage return). You can put an exit statement just after the call to the Output() method to
63be sure. If it still doesn't work, it means you're a victim of the "blank page syndrome". IE
64used in conjunction with the Acrobat plug-in suffers from many bugs. To avoid these problems
65in a reliable manner, two main techniques exist:
66<br>
67<br>
68- Disable the plug-in and use Acrobat as a helper application. To do this, launch Acrobat, go
69to the Edit menu, Preferences, Internet, and uncheck "Display PDF in browser". Then, the next
70time you load a PDF in IE, it displays the dialog box "Open it" or "Save it to disk". Uncheck
71the option "Always ask before opening this type of file" and choose Open. From now on, PDF files
72will open automatically in an external Acrobat window.
73<br>
74The drawback of the method is that you need to alter the client configuration, which you can do
75in an intranet environment but not for the Internet.
76<br>
77<br>
78- Use a redirection technique. It consists in generating the PDF in a temporary file on the server
79and redirect the client to it. For example, at the end of the script, you can put the following:
80<div class="doc-source">
81<pre><code>//Determine a temporary file name in the current directory
82$file = basename(tempnam('.', 'tmp'));
83rename($file, $file.'.pdf');
84$file .= '.pdf';
85//Save PDF to file
86$pdf-&gt;Output($file, 'F');
87//Redirect
88header('Location: '.$file);</code></pre>
89</div>
90This method turns the dynamic PDF into a static one and avoids all troubles. But you have to do
91some cleaning in order to delete the temporary files. For example:
92<div class="doc-source">
93<pre><code>function CleanFiles($dir)
94{
95 //Delete temporary files
96 $t = time();
97 $h = opendir($dir);
98 while($file=readdir($h))
99 {
100 if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')
101 {
102 $path = $dir.'/'.$file;
103 if($t-filemtime($path)&gt;3600)
104 @unlink($path);
105 }
106 }
107 closedir($h);
108}</code></pre>
109</div>
110This function deletes all files of the form tmp*.pdf older than an hour in the specified
111directory. You may call it where you want, for example in the script which generates the PDF.
112</li>
113
114<li id='q4'>
115<p><b>4.</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>
116You have to enclose your string with double quotes, not single ones.
117</li>
118
119<li id='q5'>
120<p><b>5.</b> <span class='question'>I try to display a variable in the Header method but nothing prints.</span></p>
121You have to use the <code>global</code> keyword to access global variables, for example:
122<div class="doc-source">
123<pre><code>function Header()
124{
125 global $title;
126
127 $this-&gt;SetFont('Arial', 'B', 15);
128 $this-&gt;Cell(0, 10, $title, 1, 1, 'C');
129}
130
131$title = 'My title';</code></pre>
132</div>
133Alternatively, you can use an object property:
134<div class="doc-source">
135<pre><code>function Header()
136{
137 $this-&gt;SetFont('Arial', 'B', 15);
138 $this-&gt;Cell(0, 10, $this-&gt;title, 1, 1, 'C');
139}
140
141$pdf-&gt;title = 'My title';</code></pre>
142</div>
143</li>
144
145<li id='q6'>
146<p><b>6.</b> <span class='question'>I defined the Header and Footer methods in my PDF class but nothing appears.</span></p>
147You have to create an object from the PDF class, not FPDF:
148<div class="doc-source">
149<pre><code>$pdf = new PDF();</code></pre>
150</div>
151</li>
152
153<li id='q7'>
154<p><b>7.</b> <span class='question'>Accented characters are replaced by some strange characters like é.</span></p>
155Don't use UTF-8 encoding. Standard FPDF fonts use ISO-8859-1 or Windows-1252.
156It is possible to perform a conversion to ISO-8859-1 with utf8_decode():
157<div class="doc-source">
158<pre><code>$str = utf8_decode($str);</code></pre>
159</div>
160But some characters such as Euro won't be translated correctly. If the iconv extension is available, the
161right way to do it is the following:
162<div class="doc-source">
163<pre><code>$str = iconv('UTF-8', 'windows-1252', $str);</code></pre>
164</div>
165</li>
166
167<li id='q8'>
168<p><b>8.</b> <span class='question'>I try to display the Euro symbol but it doesn't work.</span></p>
169The standard fonts have the Euro character at position 128. You can define a constant like this
170for convenience:
171<div class="doc-source">
172<pre><code>define('EURO', chr(128));</code></pre>
173</div>
174</li>
175
176<li id='q9'>
177<p><b>9.</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>
178You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return.
179You may have this other message just before:<br>
180<br>
181<b>Warning:</b> Cannot modify header information - headers already sent by (output started at script.php:X)<br>
182<br>
183It means that script.php outputs something at line X. Go to this line and fix it.
184In case the warning doesn't show, add this at the very beginning of your script:
185<div class="doc-source">
186<pre><code>ob_end_clean();</code></pre>
187</div>
188If you still don't see it, disable zlib.output_compression in your php.ini.
189</li>
190
191<li id='q10'>
192<p><b>10.</b> <span class='question'>I draw a frame with very precise dimensions, but when printed I notice some differences.</span></p>
193To respect dimensions, select "None" for the Page Scaling setting instead of "Shrink to Printable Area" in the print dialog box.
194</li>
195
196<li id='q11'>
197<p><b>11.</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>
198Printers have physical margins (different depending on the models); it is therefore impossible to remove
199them and print on the whole surface of the paper.
200</li>
201
202<li id='q12'>
203<p><b>12.</b> <span class='question'>How can I put a background in my PDF?</span></p>
204For a picture, call Image() in the Header() method, before any other output. To set a background color, use Rect().
205</li>
206
207<li id='q13'>
208<p><b>13.</b> <span class='question'>How can I set a specific header or footer on the first page?</span></p>
209Simply test the page number:
210<div class="doc-source">
211<pre><code>function Header()
212{
213 if($this-&gt;PageNo()==1)
214 {
215 //First page
216 ...
217 }
218 else
219 {
220 //Other pages
221 ...
222 }
223}</code></pre>
224</div>
225</li>
226
227<li id='q14'>
228<p><b>14.</b> <span class='question'>I'd like to use extensions provided by different scripts. How can I combine them?</span></p>
229Use an inheritance chain. If you have two classes, say A in a.php:
230<div class="doc-source">
231<pre><code>require('fpdf.php');
232
233class A extends FPDF
234{
235...
236}</code></pre>
237</div>
238and B in b.php:
239<div class="doc-source">
240<pre><code>require('fpdf.php');
241
242class B extends FPDF
243{
244...
245}</code></pre>
246</div>
247then make B extend A:
248<div class="doc-source">
249<pre><code>require('a.php');
250
251class B extends A
252{
253...
254}</code></pre>
255</div>
256and make your own class extend B:
257<div class="doc-source">
258<pre><code>require('b.php');
259
260class PDF extends B
261{
262...
263}
264
265$pdf = new PDF();</code></pre>
266</div>
267</li>
268
269<li id='q15'>
270<p><b>15.</b> <span class='question'>How can I send the PDF by email?</span></p>
271As any other file, but an easy way is to use <a href="http://phpmailer.codeworxtech.com">PHPMailer</a> and
272its in-memory attachment:
273<div class="doc-source">
274<pre><code>$mail = new PHPMailer();
275...
276$doc = $pdf-&gt;Output('', 'S');
277$mail-&gt;AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
278$mail-&gt;Send();</code></pre>
279</div>
280</li>
281
282<li id='q16'>
283<p><b>16.</b> <span class='question'>What's the limit of the file sizes I can generate with FPDF?</span></p>
284There is no particular limit. There are some constraints, however:
285<br>
286<br>
287- The maximum memory size allocated to PHP scripts is usually 8MB. For very big documents,
288especially with images, this limit may be reached (the file being built into memory). The
289parameter is configured in the php.ini file.
290<br>
291<br>
292- The maximum execution time allocated defaults to 30 seconds. This limit can of course be easily
293reached. It is configured in php.ini and may be altered dynamically with set_time_limit().
294<br>
295<br>
296- Browsers generally have a 5 minute time-out. If you send the PDF directly to the browser and
297reach the limit, it will be lost. It is therefore advised for very big documents to
298generate them in a file, and to send some data to the browser from time to time (with a call
299to flush() to force the output). When the document is finished, you can send a redirection to
300it or create a link.
301<br>
302Remark: even if the browser times out, the script may continue to run on the server.
303</li>
304
305<li id='q17'>
306<p><b>17.</b> <span class='question'>Can I modify a PDF with FPDF?</span></p>
307It is possible to import pages from an existing PDF document thanks to the FPDI extension:<br>
308<br>
309<a href="http://www.setasign.de/products/pdf-php-solutions/fpdi/" target="_blank">http://www.setasign.de/products/pdf-php-solutions/fpdi/</a><br>
310<br>
311You can then add some content to them.
312</li>
313
314<li id='q18'>
315<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>
316No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from
317a PDF. It is provided with the Xpdf package:<br>
318<br>
319<a href="http://www.foolabs.com/xpdf/" target="_blank">http://www.foolabs.com/xpdf/</a>
320</li>
321
322<li id='q19'>
323<p><b>19.</b> <span class='question'>Can I convert an HTML page to PDF with FPDF?</span></p>
324Not real-world pages. But a GPL C utility does exist, htmldoc, which allows to do it and gives good results:<br>
325<br>
326<a href="http://www.htmldoc.org" target="_blank">http://www.htmldoc.org</a>
327</li>
328
329<li id='q20'>
330<p><b>20.</b> <span class='question'>Can I concatenate PDF files with FPDF?</span></p>
331Not directly, but it is possible to use <a href="http://www.setasign.de/products/pdf-php-solutions/fpdi/demos/concatenate-fake/" target="_blank">FPDI</a>
332to perform this task. Some free command-line tools also exist:<br>
333<br>
334<a href="http://thierry.schmit.free.fr/spip/spip.php?article15&amp;lang=en" target="_blank">mbtPdfAsm</a><br>
335<a href="http://www.accesspdf.com/pdftk/" target="_blank">pdftk</a>
336</li>
337</ul>
338</body>
339</html>
Note: See TracBrowser for help on using the repository browser.