source: trunk/phpgwapi/inc/fpdf/FAQ.htm @ 2

Revision 2, 15.2 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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>
31FPDF is Freeware (it is stated at the beginning of the source file). There is no usage
32restriction. You may embed it freely in your application (commercial or not), with or
33without 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>
35These "weird" characters are in fact the actual content of your PDF. This behaviour is a bug of
36IE. When it first receives an HTML page, then a PDF from the same URL, it displays it directly
37without launching Acrobat. This happens frequently during the development stage: on the least
38script error, an HTML page is sent, and after correction, the PDF arrives.
39<BR>
40To solve the problem, simply quit and restart IE. You can also go to another URL and come
41back.
42<BR>
43To avoid this kind of inconvenience during the development, you can generate the PDF directly
44to 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>
46First of all, check that you send nothing to the browser after the PDF (not even a space or a
47carriage return). You can put an exit statement just after the call to the Output() method to
48be sure.
49<BR>
50If it still doesn't work, it means you're a victim of the "blank page syndrome". IE used in
51conjunction with the Acrobat plug-in suffers from numerous bugs, in all versions. You should
52test your application with as many IE versions as possible (at least if you're on the Internet).
53The problem occurs mostly with the POST method, so it is strongly advised to avoid it (all the
54more that it causes other problems, see the next question). The GET works better but may fail
55when the URL becomes too long: don't use a query string with more than 45 characters. However, a
56tip exists to exceed this limit: end the URL with .pdf, which tricks IE. If you use a form, you
57can add a hidden field at the last position:
58<BR>
59<BR>
60<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
61<TT>
62&lt;INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;ext&quot; VALUE=&quot;.pdf&quot;&gt;
63</TT>
64</TD></TR></TABLE><BR>
65The usage of PHP sessions also often causes trouble (avoid using HTTP headers preventing caching).
66See question 5 for a workaround.
67<BR>
68<BR>
69To 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
73the File menu, Preferences, General, uncheck the option "Web Browser Integration" (for Acrobat
745: Edit, Preferences, Options, "Display PDF in Browser"). Then, the next time you load a PDF in
75IE, it displays the dialog box "Open it" or "Save it to disk". Uncheck the option "Always ask
76before opening this type of file" and choose Open. From now on, PDF files will open
77automatically in an external Acrobat window.
78<BR>
79The drawback of the method is that you need to alter the client configuration, which you can do
80in 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
84server and redirect the client on it (by using JavaScript, not the Location HTTP header which
85also 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-&gt;Output($file);<BR>
94//JavaScript redirection<BR>
95echo &quot;&lt;HTML&gt;&lt;SCRIPT&gt;document.location='getpdf.php?f=$file';&lt;/SCRIPT&gt;&lt;/HTML&gt;&quot;;
96</TT>
97</TD></TR></TABLE><BR>
98Then create the getpdf.php file with this:
99<BR>
100<BR>
101<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
102<TT>
103&lt;?php<BR>
104$f=$HTTP_GET_VARS['f'];<BR>
105//Check file (don't skip it!)<BR>
106if(substr($f,0,3)!='tmp' or strpos($f,'/') or strpos($f,'\\'))<BR>
107&nbsp;&nbsp;&nbsp;&nbsp;die('Incorrect file name');<BR>
108if(!file_exists($f))<BR>
109&nbsp;&nbsp;&nbsp;&nbsp;die('File does not exist');<BR>
110//Handle special IE request if needed<BR>
111if($HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype')<BR>
112{<BR>
113&nbsp;&nbsp;&nbsp;&nbsp;Header('Content-Type: application/pdf');<BR>
114&nbsp;&nbsp;&nbsp;&nbsp;exit;<BR>
115}<BR>
116//Output PDF<BR>
117Header('Content-Type: application/pdf');<BR>
118Header('Content-Length: '.filesize($f));<BR>
119readfile($f);<BR>
120//Remove file<BR>
121unlink($f);<BR>
122exit;<BR>
123?&gt;
124</TT>
125</TD></TR></TABLE><BR>
126This method works in most cases but IE6 can still experience trouble. The "ultimate" method
127consists 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>
134rename($file,$file.'.pdf');<BR>
135$file.='.pdf';<BR>
136//Save PDF to file<BR>
137$pdf-&gt;Output($file);<BR>
138//JavaScript redirection<BR>
139echo &quot;&lt;HTML&gt;&lt;SCRIPT&gt;document.location='$file';&lt;/SCRIPT&gt;&lt;/HTML&gt;&quot;;
140</TT>
141</TD></TR></TABLE><BR>
142This method turns the dynamic PDF into a static one and avoids all troubles. But you have to do
143some cleaning in order to delete the temporary files. For instance:
144<BR>
145<BR>
146<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
147<TT>
148function CleanFiles($dir)<BR>
149{<BR>
150&nbsp;&nbsp;&nbsp;&nbsp;//Delete temporary files<BR>
151&nbsp;&nbsp;&nbsp;&nbsp;$t=time();<BR>
152&nbsp;&nbsp;&nbsp;&nbsp;$h=opendir($dir);<BR>
153&nbsp;&nbsp;&nbsp;&nbsp;while($file=readdir($h))<BR>
154&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
155&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(substr($file,0,3)=='tmp' and substr($file,-4)=='.pdf')<BR>
156&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>
157&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$path=$dir.'/'.$file;<BR>
158&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($t-filemtime($path)&gt;3600)<BR>
159&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@unlink($path);<BR>
160&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
161&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
162&nbsp;&nbsp;&nbsp;&nbsp;closedir($h);<BR>
163}
164</TT>
165</TD></TR></TABLE><BR>
166This function deletes all files of the form tmp*.pdf older than an hour in the specified
167directory. You may call it where you want, for instance in the script which generates the PDF.
168<BR>
169<BR>
170Remark: it is necessary to open the PDF in a new window, as you can't go backwards due to the
171redirection.
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>
173It's a problem affecting some versions of IE (especially the first 5.5). See the previous
174question 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>
176It's a problem affecting some versions of IE. To work around it, add the following line before
177session_start():
178<BR>
179<BR>
180<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
181<TT>
182session_cache_limiter('private');
183</TT>
184</TD></TR></TABLE><BR>
185or 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>
187The problem may be fixed by adding this line:<BR>
188<BR>
189<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
190<TT>
191Header('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>
196When 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
198numbers get truncated. Therefore you shouldn't make a call to setlocale() before including the class.
199On Unix, you shouldn't set the LC_ALL environment variable neither, for it is equivalent to a
200setlocale() 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>
202Acrobat 5 has a bug and is unable to display transparent monochrome images (i.e. with 1 bit per
203pixel). 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>
205You must send nothing to the browser except the PDF itself: no HTML, no space, no carriage return,
206neither 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>
208You have to use the <TT>global</TT> keyword, for instance:
209<BR>
210<BR>
211<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
212<TT>
213function Header()<BR>
214{<BR>
215&nbsp;&nbsp;&nbsp;&nbsp;global $title;<BR>
216<BR>
217&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;SetFont('Arial','B',15);<BR>
218&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;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>
224You 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>
233You 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>
235The standard fonts have the euro character at position 128. You can define a constant like this
236for convenience:
237<BR>
238<BR>
239<TABLE WIDTH="100%" BGCOLOR="#E0E0E0"><TR><TD>
240<TT>
241define('EURO',chr(128));
242</TT>
243</TD></TR></TABLE><BR>
244Note: 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>
246To 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>
248All printers have physical margins (different depending on the model), it is therefore impossible
249to 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>
251There 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,
255especially with images, this limit may be reached (the file being built into memory). The
256parameter 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
260reached. 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
264reach the limit, it will be lost. It is therefore advised for very big documents to
265generate them in a file, and to send some data to the browser from time to time (for instance
266page 1, page 2... with flush() to force the output). When the document is finished, you can send
267a redirection on it with JavaScript or create a link.
268<BR>
269Remark: 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>
271No.
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>
273No. But a GPL C utility does exist, pdftotext, which is able to extract the textual content from
274a 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>
278No. 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>
282No. 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>
Note: See TracBrowser for help on using the repository browser.