Skip to content

Commit 3bbe50c

Browse files
committed
initializing fpdf
1 parent 55290e6 commit 3bbe50c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+12219
-0
lines changed

application/libraries/Pdf.php

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

0 commit comments

Comments
 (0)