1 | <HTML> |
---|
2 | <HEAD> |
---|
3 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> |
---|
4 | <TITLE>FAQ</TITLE> |
---|
5 | <LINK TYPE="text/css" REL="stylesheet" HREF="fpdf.css"> |
---|
6 | </HEAD> |
---|
7 | <BODY> |
---|
8 | <H2>FAQ</H2> |
---|
9 | <B>1.</B> <A HREF='#1'>What's exactly the license of FPDF? Are there any usage restrictions?</A><BR> |
---|
10 | <B>2.</B> <A HREF='#2'>When I try to create a PDF, a lot of weird characters show on the screen. Why?</A><BR> |
---|
11 | <B>3.</B> <A HREF='#3'>I try to generate a PDF and IE displays a blank page. What happens?</A><BR> |
---|
12 | <B>4.</B> <A HREF='#4'>I send parameters using the POST method and the values don't appear in the PDF.</A><BR> |
---|
13 | <B>5.</B> <A HREF='#5'>When I use a PHP session, IE doesn't display my PDF any more but asks me to download it.</A><BR> |
---|
14 | <B>6.</B> <A HREF='#6'>When I'm on SSL, IE can't open the PDF.</A><BR> |
---|
15 | <B>7.</B> <A HREF='#7'>When I execute a script I get the message "FPDF error: Don't alter the locale before including class file".</A><BR> |
---|
16 | <B>8.</B> <A HREF='#8'>I try to put a PNG and Acrobat says "There was an error processing a page. A drawing error occurred".</A><BR> |
---|
17 | <B>9.</B> <A HREF='#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)</A><BR> |
---|
18 | <B>10.</B> <A HREF='#10'>I try to display a variable in the Header method but nothing prints.</A><BR> |
---|
19 | <B>11.</B> <A HREF='#11'>I defined the Header and Footer methods in my PDF class but nothing appears.</A><BR> |
---|
20 | <B>12.</B> <A HREF='#12'>I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.</A><BR> |
---|
21 | <B>13.</B> <A HREF='#13'>I try to put the euro symbol but it doesn't work.</A><BR> |
---|
22 | <B>14.</B> <A HREF='#14'>I draw a frame with very precise dimensions, but when printed I notice some differences.</A><BR> |
---|
23 | <B>15.</B> <A HREF='#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?</A><BR> |
---|
24 | <B>16.</B> <A HREF='#16'>What's the limit of the file sizes I can generate with FPDF?</A><BR> |
---|
25 | <B>17.</B> <A HREF='#17'>Can I modify a PDF with FPDF?</A><BR> |
---|
26 | <B>18.</B> <A HREF='#18'>I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?</A><BR> |
---|
27 | <B>19.</B> <A HREF='#19'>Can I convert an HTML page to PDF with FPDF?</A><BR> |
---|
28 | <B>20.</B> <A HREF='#20'>Can I concatenate PDF files with FPDF?</A><BR> |
---|
29 | <BR><BR> |
---|
30 | <P><A NAME='1'></A><B>1.</B> <FONT CLASS='st'>What's exactly the license of FPDF? Are there any usage restrictions?</FONT></P> |
---|
31 | FPDF is Freeware (it is stated at the beginning of the source file). There is no usage |
---|
32 | restriction. You may embed it freely in your application (commercial or not), with or |
---|
33 | without modification. You may redistribute it, too. |
---|
34 | <P><A NAME='2'></A><B>2.</B> <FONT CLASS='st'>When I try to create a PDF, a lot of weird characters show on the screen. Why?</FONT></P> |
---|
35 | These "weird" characters are in fact the actual content of your PDF. This behaviour is a bug of |
---|
36 | IE. When it first receives an HTML page, then a PDF from the same URL, it displays it directly |
---|
37 | without launching Acrobat. This happens frequently during the development stage: on the least |
---|
38 | script error, an HTML page is sent, and after correction, the PDF arrives. |
---|
39 | <BR> |
---|
40 | To solve the problem, simply quit and restart IE. You can also go to another URL and come |
---|
41 | back. |
---|
42 | <BR> |
---|
43 | To avoid this kind of inconvenience during the development, you can generate the PDF directly |
---|
44 | to a file and open it through the explorer. |
---|
45 | <P><A NAME='3'></A><B>3.</B> <FONT CLASS='st'>I try to generate a PDF and IE displays a blank page. What happens?</FONT></P> |
---|
46 | First of all, check that you send nothing to the browser after the PDF (not even a space or a |
---|
47 | carriage return). You can put an exit statement just after the call to the Output() method to |
---|
48 | be sure. |
---|
49 | <BR> |
---|
50 | If it still doesn't work, it means you're a victim of the "blank page syndrome". IE used in |
---|
51 | conjunction with the Acrobat plug-in suffers from numerous bugs, in all versions. You should |
---|
52 | test your application with as many IE versions as possible (at least if you're on the Internet). |
---|
53 | The problem occurs mostly with the POST method, so it is strongly advised to avoid it (all the |
---|
54 | more that it causes other problems, see the next question). The GET works better but may fail |
---|
55 | when the URL becomes too long: don't use a query string with more than 45 characters. However, a |
---|
56 | tip exists to exceed this limit: end the URL with .pdf, which tricks IE. If you use a form, you |
---|
57 | can add a hidden field at the last position: |
---|
58 | <BR> |
---|
59 | <BR> |
---|
60 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
61 | <TT> |
---|
62 | <INPUT TYPE="HIDDEN" NAME="ext" VALUE=".pdf"> |
---|
63 | </TT> |
---|
64 | </TD></TR></TABLE><BR> |
---|
65 | The usage of PHP sessions also often causes trouble (avoid using HTTP headers preventing caching). |
---|
66 | See question 5 for a workaround. |
---|
67 | <BR> |
---|
68 | <BR> |
---|
69 | To avoid all these problems in a reliable manner, two main techniques exist: |
---|
70 | <BR> |
---|
71 | <BR> |
---|
72 | - Disable the plug-in and use Acrobat as a helper application. To do this, launch Acrobat; in |
---|
73 | the File menu, Preferences, General, uncheck the option "Web Browser Integration" (for Acrobat |
---|
74 | 5: Edit, Preferences, Options, "Display PDF in Browser"). Then, the next time you load a PDF in |
---|
75 | IE, it displays the dialog box "Open it" or "Save it to disk". Uncheck the option "Always ask |
---|
76 | before opening this type of file" and choose Open. From now on, PDF files will open |
---|
77 | automatically in an external Acrobat window. |
---|
78 | <BR> |
---|
79 | The drawback of the method is that you need to alter the client configuration, which you can do |
---|
80 | in an intranet environment but not for the Internet. |
---|
81 | <BR> |
---|
82 | <BR> |
---|
83 | - Use a redirection technique. It consists in generating the PDF in a temporary file on the |
---|
84 | server and redirect the client on it (by using JavaScript, not the Location HTTP header which |
---|
85 | also causes trouble). For instance, at the end of the script, you can put the following: |
---|
86 | <BR> |
---|
87 | <BR> |
---|
88 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
89 | <TT> |
---|
90 | //Determine a temporary file name in the current directory<BR> |
---|
91 | $file=basename(tempnam(getcwd(),'tmp'));<BR> |
---|
92 | //Save PDF to file<BR> |
---|
93 | $pdf->Output($file);<BR> |
---|
94 | //JavaScript redirection<BR> |
---|
95 | echo "<HTML><SCRIPT>document.location='getpdf.php?f=$file';</SCRIPT></HTML>"; |
---|
96 | </TT> |
---|
97 | </TD></TR></TABLE><BR> |
---|
98 | Then create the getpdf.php file with this: |
---|
99 | <BR> |
---|
100 | <BR> |
---|
101 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
102 | <TT> |
---|
103 | <?php<BR> |
---|
104 | $f=$HTTP_GET_VARS['f'];<BR> |
---|
105 | //Check file (don't skip it!)<BR> |
---|
106 | if(substr($f,0,3)!='tmp' or strpos($f,'/') or strpos($f,'\\'))<BR> |
---|
107 | die('Incorrect file name');<BR> |
---|
108 | if(!file_exists($f))<BR> |
---|
109 | die('File does not exist');<BR> |
---|
110 | //Handle special IE request if needed<BR> |
---|
111 | if($HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype')<BR> |
---|
112 | {<BR> |
---|
113 | Header('Content-Type: application/pdf');<BR> |
---|
114 | exit;<BR> |
---|
115 | }<BR> |
---|
116 | //Output PDF<BR> |
---|
117 | Header('Content-Type: application/pdf');<BR> |
---|
118 | Header('Content-Length: '.filesize($f));<BR> |
---|
119 | readfile($f);<BR> |
---|
120 | //Remove file<BR> |
---|
121 | unlink($f);<BR> |
---|
122 | exit;<BR> |
---|
123 | ?> |
---|
124 | </TT> |
---|
125 | </TD></TR></TABLE><BR> |
---|
126 | This method works in most cases but IE6 can still experience trouble. The "ultimate" method |
---|
127 | consists in redirecting directly to the temporary file. The file name must therefore end with .pdf: |
---|
128 | <BR> |
---|
129 | <BR> |
---|
130 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
131 | <TT> |
---|
132 | //Determine a temporary file name in the current directory<BR> |
---|
133 | $file=basename(tempnam(getcwd(),'tmp'));<BR> |
---|
134 | rename($file,$file.'.pdf');<BR> |
---|
135 | $file.='.pdf';<BR> |
---|
136 | //Save PDF to file<BR> |
---|
137 | $pdf->Output($file);<BR> |
---|
138 | //JavaScript redirection<BR> |
---|
139 | echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>"; |
---|
140 | </TT> |
---|
141 | </TD></TR></TABLE><BR> |
---|
142 | This method turns the dynamic PDF into a static one and avoids all troubles. But you have to do |
---|
143 | some cleaning in order to delete the temporary files. For instance: |
---|
144 | <BR> |
---|
145 | <BR> |
---|
146 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
147 | <TT> |
---|
148 | function CleanFiles($dir)<BR> |
---|
149 | {<BR> |
---|
150 | //Delete temporary files<BR> |
---|
151 | $t=time();<BR> |
---|
152 | $h=opendir($dir);<BR> |
---|
153 | while($file=readdir($h))<BR> |
---|
154 | {<BR> |
---|
155 | if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')<BR> |
---|
156 | {<BR> |
---|
157 | $path=$dir.'/'.$file;<BR> |
---|
158 | if($t-filemtime($path)>3600)<BR> |
---|
159 | @unlink($path);<BR> |
---|
160 | }<BR> |
---|
161 | }<BR> |
---|
162 | closedir($h);<BR> |
---|
163 | } |
---|
164 | </TT> |
---|
165 | </TD></TR></TABLE><BR> |
---|
166 | This function deletes all files of the form tmp*.pdf older than an hour in the specified |
---|
167 | directory. You may call it where you want, for instance in the script which generates the PDF. |
---|
168 | <BR> |
---|
169 | <BR> |
---|
170 | Remark: it is necessary to open the PDF in a new window, as you can't go backwards due to the |
---|
171 | redirection. |
---|
172 | <P><A NAME='4'></A><B>4.</B> <FONT CLASS='st'>I send parameters using the POST method and the values don't appear in the PDF.</FONT></P> |
---|
173 | It's a problem affecting some versions of IE (especially the first 5.5). See the previous |
---|
174 | question for the ways to work around it. |
---|
175 | <P><A NAME='5'></A><B>5.</B> <FONT CLASS='st'>When I use a PHP session, IE doesn't display my PDF any more but asks me to download it.</FONT></P> |
---|
176 | It's a problem affecting some versions of IE. To work around it, add the following line before |
---|
177 | session_start(): |
---|
178 | <BR> |
---|
179 | <BR> |
---|
180 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
181 | <TT> |
---|
182 | session_cache_limiter('private'); |
---|
183 | </TT> |
---|
184 | </TD></TR></TABLE><BR> |
---|
185 | or do a redirection as explained in question 3. |
---|
186 | <P><A NAME='6'></A><B>6.</B> <FONT CLASS='st'>When I'm on SSL, IE can't open the PDF.</FONT></P> |
---|
187 | The problem may be fixed by adding this line:<BR> |
---|
188 | <BR> |
---|
189 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
190 | <TT> |
---|
191 | Header('Pragma: public'); |
---|
192 | </TT> |
---|
193 | </TD></TR></TABLE><BR> |
---|
194 | |
---|
195 | <P><A NAME='7'></A><B>7.</B> <FONT CLASS='st'>When I execute a script I get the message "FPDF error: Don't alter the locale before including class file".</FONT></P> |
---|
196 | When the decimal separator is configured as a comma before including a file, there is a |
---|
197 | <A HREF="http://bugs.php.net/bug.php?id=17105" TARGET="_blank">bug</A> in some PHP versions and decimal |
---|
198 | numbers get truncated. Therefore you shouldn't make a call to setlocale() before including the class. |
---|
199 | On Unix, you shouldn't set the LC_ALL environment variable neither, for it is equivalent to a |
---|
200 | setlocale() call. |
---|
201 | <P><A NAME='8'></A><B>8.</B> <FONT CLASS='st'>I try to put a PNG and Acrobat says "There was an error processing a page. A drawing error occurred".</FONT></P> |
---|
202 | Acrobat 5 has a bug and is unable to display transparent monochrome images (i.e. with 1 bit per |
---|
203 | pixel). Remove transparency or save your image in 16 colors (4 bits per pixel) or more. |
---|
204 | <P><A NAME='9'></A><B>9.</B> <FONT CLASS='st'>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)</FONT></P> |
---|
205 | You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return, |
---|
206 | neither before nor after. The script outputs something at line X. |
---|
207 | <P><A NAME='10'></A><B>10.</B> <FONT CLASS='st'>I try to display a variable in the Header method but nothing prints.</FONT></P> |
---|
208 | You have to use the <TT>global</TT> keyword, for instance: |
---|
209 | <BR> |
---|
210 | <BR> |
---|
211 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
212 | <TT> |
---|
213 | function Header()<BR> |
---|
214 | {<BR> |
---|
215 | global $title;<BR> |
---|
216 | <BR> |
---|
217 | $this->SetFont('Arial','B',15);<BR> |
---|
218 | $this->Cell(0,10,$title,1,1,'C');<BR> |
---|
219 | } |
---|
220 | </TT> |
---|
221 | </TD></TR></TABLE><BR> |
---|
222 | |
---|
223 | <P><A NAME='11'></A><B>11.</B> <FONT CLASS='st'>I defined the Header and Footer methods in my PDF class but nothing appears.</FONT></P> |
---|
224 | You have to create an object from the PDF class, not FPDF:<BR> |
---|
225 | <BR> |
---|
226 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
227 | <TT> |
---|
228 | $pdf=new PDF(); |
---|
229 | </TT> |
---|
230 | </TD></TR></TABLE><BR> |
---|
231 | |
---|
232 | <P><A NAME='12'></A><B>12.</B> <FONT CLASS='st'>I can't make line breaks work. I put \n in the string printed by MultiCell but it doesn't work.</FONT></P> |
---|
233 | You have to enclose your string with double quotes, not single ones. |
---|
234 | <P><A NAME='13'></A><B>13.</B> <FONT CLASS='st'>I try to put the euro symbol but it doesn't work.</FONT></P> |
---|
235 | The standard fonts have the euro character at position 128. You can define a constant like this |
---|
236 | for convenience: |
---|
237 | <BR> |
---|
238 | <BR> |
---|
239 | <TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD> |
---|
240 | <TT> |
---|
241 | define('EURO',chr(128)); |
---|
242 | </TT> |
---|
243 | </TD></TR></TABLE><BR> |
---|
244 | Note: Acrobat 4 or higher is required to display euro. |
---|
245 | <P><A NAME='14'></A><B>14.</B> <FONT CLASS='st'>I draw a frame with very precise dimensions, but when printed I notice some differences.</FONT></P> |
---|
246 | To respect dimensions, you have to uncheck the option "Fit to page" in the print dialog box. |
---|
247 | <P><A NAME='15'></A><B>15.</B> <FONT CLASS='st'>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?</FONT></P> |
---|
248 | All printers have physical margins (different depending on the model), it is therefore impossible |
---|
249 | to remove them and print on the totality of the paper. |
---|
250 | <P><A NAME='16'></A><B>16.</B> <FONT CLASS='st'>What's the limit of the file sizes I can generate with FPDF?</FONT></P> |
---|
251 | There is no particular limit. There are some constraints however: |
---|
252 | <BR> |
---|
253 | <BR> |
---|
254 | - The maximum memory size allocated to PHP scripts defaults to 8MB. For very big documents, |
---|
255 | especially with images, this limit may be reached (the file being built into memory). The |
---|
256 | parameter is configured in the php.ini file. |
---|
257 | <BR> |
---|
258 | <BR> |
---|
259 | - The maximum execution time allocated defaults to 30 seconds. This limit can of course be easily |
---|
260 | reached. It is configured in php.ini and may be altered dynamically with set_time_limit(). |
---|
261 | <BR> |
---|
262 | <BR> |
---|
263 | - Browsers generally have a 5 minute time-out. If you send the PDF directly to the browser and |
---|
264 | reach the limit, it will be lost. It is therefore advised for very big documents to |
---|
265 | generate them in a file, and to send some data to the browser from time to time (for instance |
---|
266 | page 1, page 2... with flush() to force the output). When the document is finished, you can send |
---|
267 | a redirection on it with JavaScript or create a link. |
---|
268 | <BR> |
---|
269 | Remark: even when the browser goes in time-out, the script may continue to run on the server. |
---|
270 | <P><A NAME='17'></A><B>17.</B> <FONT CLASS='st'>Can I modify a PDF with FPDF?</FONT></P> |
---|
271 | No. |
---|
272 | <P><A NAME='18'></A><B>18.</B> <FONT CLASS='st'>I'd like to make a search engine in PHP and index PDF files. Can I do it with FPDF?</FONT></P> |
---|
273 | No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from |
---|
274 | a PDF. It is provided with the Xpdf package:<BR> |
---|
275 | <BR> |
---|
276 | <A HREF="http://www.foolabs.com/xpdf/" TARGET="_blank">http://www.foolabs.com/xpdf/</A> |
---|
277 | <P><A NAME='19'></A><B>19.</B> <FONT CLASS='st'>Can I convert an HTML page to PDF with FPDF?</FONT></P> |
---|
278 | No. But a GPL C utility does exist, htmldoc, which allows to do it and gives good results:<BR> |
---|
279 | <BR> |
---|
280 | <A HREF="http://www.easysw.com/htmldoc/" TARGET="_blank">http://www.easysw.com/htmldoc/</A> |
---|
281 | <P><A NAME='20'></A><B>20.</B> <FONT CLASS='st'>Can I concatenate PDF files with FPDF?</FONT></P> |
---|
282 | No. But a free C utility exists to perform this task:<BR> |
---|
283 | <BR> |
---|
284 | <A HREF="http://thierry.schmit.free.fr/dev/mbtPdfAsm/enMbtPdfAsm2.html" TARGET="_blank">http://thierry.schmit.free.fr/dev/mbtPdfAsm/enMbtPdfAsm2.html</A> |
---|
285 | </BODY> |
---|
286 | </HTML> |
---|