source: branches/version-2_11-dev/data/module/fpdf/tutorial/tuto1.htm @ 20993

Revision 20993, 4.7 KB checked in by Seasoft, 13 years ago (diff)

#1374 (依存ライブラリのアップデート)

  • FPDF 1.6 -> 1.7
  • FPDI 1.4 -> 1.4.1 (配置パスをFPDFから分離)
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>Minimal example</title>
6<link type="text/css" rel="stylesheet" href="../fpdf.css">
7</head>
8<body>
9<h1>Minimal example</h1>
10Let's start with the classic example:
11<div class="source">
12<pre><code>&lt;?php
13<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
14
15</span>$pdf <span class="kw">= new </span>FPDF<span class="kw">();
16</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
17</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">'B'</span><span class="kw">,</span>16<span class="kw">);
18</span>$pdf<span class="kw">-&gt;</span>Cell<span class="kw">(</span>40<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Hello World!'</span><span class="kw">);
19</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
20</span>?&gt;</code></pre>
21</div>
22<p class='demo'><a href='tuto1.php' target='_blank' class='demo'>[Demo]</a></p>
23After including the library file, we create an FPDF object.
24The <a href='../doc/fpdf.htm'>FPDF()</a> constructor is used here with the default values: pages are in A4 portrait and
25the unit of measure is millimeter. It could have been specified explicitly with:
26<div class="source">
27<pre><code>$pdf <span class="kw">= new </span>FPDF<span class="kw">(</span><span class="str">'P'</span><span class="kw">,</span><span class="str">'mm'</span><span class="kw">,</span><span class="str">'A4'</span><span class="kw">);
28</span></code></pre>
29</div>
30It's possible to use landscape (<code>L</code>), other page sizes (such as <code>Letter</code> and
31<code>Legal</code>) and units (<code>pt</code>, <code>cm</code>, <code>in</code>).
32<br>
33<br>
34There's no page at the moment, so we have to add one with <a href='../doc/addpage.htm'>AddPage()</a>. The origin
35is at the upper-left corner and the current position is by default set at 1 cm from the
36borders; the margins can be changed with <a href='../doc/setmargins.htm'>SetMargins()</a>.
37<br>
38<br>
39Before we can print text, it's mandatory to select a font with <a href='../doc/setfont.htm'>SetFont()</a>, otherwise the
40document would be invalid. We choose Arial bold 16:
41<div class="source">
42<pre><code>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">'B'</span><span class="kw">,</span>16<span class="kw">);
43</span></code></pre>
44</div>
45We could have specified italics with I, underlined with U or a regular font with an empty string
46(or any combination). Note that the font size is given in points, not millimeters (or another user
47unit); it's the only exception. The other standard fonts are Times, Courier, Symbol and ZapfDingbats.
48<br>
49<br>
50We can now print a cell with <a href='../doc/cell.htm'>Cell()</a>. A cell is a rectangular area, possibly framed,
51which contains a line of text. It is output at the current position. We specify its dimensions,
52its text (centered or aligned), if borders should be drawn, and where the current position
53moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:
54<div class="source">
55<pre><code>$pdf<span class="kw">-&gt;</span>Cell<span class="kw">(</span>40<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Hello World !'</span><span class="kw">,</span>1<span class="kw">);
56</span></code></pre>
57</div>
58To add a new cell next to it with centered text and go to the next line, we would do:
59<div class="source">
60<pre><code>$pdf<span class="kw">-&gt;</span>Cell<span class="kw">(</span>60<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Powered by FPDF.'</span><span class="kw">,</span>0<span class="kw">,</span>1<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
61</span></code></pre>
62</div>
63Remark: the line break can also be done with <a href='../doc/ln.htm'>Ln()</a>. This method additionnaly allows to specify
64the height of the break.
65<br>
66<br>
67Finally, the document is closed and sent to the browser with <a href='../doc/output.htm'>Output()</a>. We could have saved
68it to a file by passing the desired file name.
69<br>
70<br>
71<strong>Caution:</strong> in case when the PDF is sent to the browser, nothing else must be output by the
72script, neither before nor after (no HTML, not even a space or a carriage return). If you send something
73before, you will get the error message: "Some data has already been output, can't send PDF file". If you
74send something after, the document might not display.
75</body>
76</html>
Note: See TracBrowser for help on using the repository browser.