[2] | 1 | <HTML> |
---|
| 2 | <HEAD> |
---|
| 3 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> |
---|
| 4 | <TITLE>Minimal example</TITLE> |
---|
| 5 | <LINK TYPE="text/css" REL="stylesheet" HREF="../fpdf.css"> |
---|
| 6 | </HEAD> |
---|
| 7 | <BODY> |
---|
| 8 | <H2>Minimal example</H2> |
---|
| 9 | Let's start with the classic example: |
---|
| 10 | <BR> |
---|
| 11 | <BR> |
---|
| 12 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px"> |
---|
| 13 | <NOBR><code><font color="#000000"> |
---|
| 14 | <?php<br>define<font class="kw">(</font><font class="str">'FPDF_FONTPATH'</font><font class="kw">,</font><font class="str">'font/'</font><font class="kw">);<br>require(</font><font class="str">'fpdf.php'</font><font class="kw">);<br><br></font>$pdf<font class="kw">=new </font>FPDF<font class="kw">();<br></font>$pdf<font class="kw">-></font>AddPage<font class="kw">();<br></font>$pdf<font class="kw">-></font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>16<font class="kw">);<br></font>$pdf<font class="kw">-></font>Cell<font class="kw">(</font>40<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Hello World!'</font><font class="kw">);<br></font>$pdf<font class="kw">-></font>Output<font class="kw">();<br></font>?> |
---|
| 15 | </font> |
---|
| 16 | </code></NOBR></TD></TR></TABLE><P></P> |
---|
| 17 | <SCRIPT> |
---|
| 18 | <!-- |
---|
| 19 | if(document.location.href.indexOf('http:')==0) |
---|
| 20 | { |
---|
| 21 | document.write("<P CLASS='demo'><A HREF='tuto1.php' TARGET='_blank' CLASS='demo'>[Demo]</A></P>"); |
---|
| 22 | } |
---|
| 23 | //--> |
---|
| 24 | </SCRIPT> |
---|
| 25 | The first line defines where the font directory resides, relative to the current directory.<BR> |
---|
| 26 | Then, after including the library file, we create an FPDF object. |
---|
| 27 | The <A HREF='../doc/fpdf.htm'>FPDF()</A> constructor is used here with the default values: pages are in A4 portrait and |
---|
| 28 | the measure unit is millimeter. It could have been specified explicitly with: |
---|
| 29 | <BR> |
---|
| 30 | <BR> |
---|
| 31 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px"> |
---|
| 32 | <NOBR><code><font color="#000000"> |
---|
| 33 | $pdf<font class="kw">=new </font>FPDF<font class="kw">(</font><font class="str">'P'</font><font class="kw">,</font><font class="str">'mm'</font><font class="kw">,</font><font class="str">'A4'</font><font class="kw">);</font><br> |
---|
| 34 | </font> |
---|
| 35 | </code></NOBR></TD></TR></TABLE><P></P> |
---|
| 36 | It is possible to use landscape (<TT>L</TT>), other page formats (such as <TT>Letter</TT> and |
---|
| 37 | <TT>Legal</TT>) and measure units (<TT>pt</TT>, <TT>cm</TT>, <TT>in</TT>). |
---|
| 38 | <BR> |
---|
| 39 | <BR> |
---|
| 40 | There is no page for the moment, so we have to add one with <A HREF='../doc/addpage.htm'>AddPage()</A>. The origin |
---|
| 41 | is at the upper-left corner and the current position is by default placed at 1 cm from the |
---|
| 42 | borders; the margins can be changed with <A HREF='../doc/setmargins.htm'>SetMargins()</A>. |
---|
| 43 | <BR> |
---|
| 44 | <BR> |
---|
| 45 | Before we can print text, it is mandatory to select a font with <A HREF='../doc/setfont.htm'>SetFont()</A>, otherwise the |
---|
| 46 | document would be invalid. We choose Arial bold 16: |
---|
| 47 | <BR> |
---|
| 48 | <BR> |
---|
| 49 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px"> |
---|
| 50 | <NOBR><code><font color="#000000"> |
---|
| 51 | $pdf<font class="kw">-></font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>16<font class="kw">);</font><br> |
---|
| 52 | </font> |
---|
| 53 | </code></NOBR></TD></TR></TABLE><P></P> |
---|
| 54 | We could have specified italics with I, underlined with U or a regular font with an empty string |
---|
| 55 | (or any combination). Note that the font size is given in points, not millimeters (or another |
---|
| 56 | user unit); it is the only exception. The other standard fonts are Times, Courier, Symbol and |
---|
| 57 | ZapfDingbats. |
---|
| 58 | <BR> |
---|
| 59 | <BR> |
---|
| 60 | We can now print a cell with <A HREF='../doc/cell.htm'>Cell()</A>. A cell is a rectangular area, possibly framed, |
---|
| 61 | which contains some text. It is output at the current position. We specify its dimensions, |
---|
| 62 | its text (centered or aligned), if borders should be drawn, and where the current position |
---|
| 63 | moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this: |
---|
| 64 | <BR> |
---|
| 65 | <BR> |
---|
| 66 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px"> |
---|
| 67 | <NOBR><code><font color="#000000"> |
---|
| 68 | $pdf<font class="kw">-></font>Cell<font class="kw">(</font>40<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Hello World !'</font><font class="kw">,</font>1<font class="kw">);</font><br> |
---|
| 69 | </font> |
---|
| 70 | </code></NOBR></TD></TR></TABLE><P></P> |
---|
| 71 | To add a new cell next to it with centered text and go to the next line, we would do: |
---|
| 72 | <BR> |
---|
| 73 | <BR> |
---|
| 74 | <TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px"> |
---|
| 75 | <NOBR><code><font color="#000000"> |
---|
| 76 | $pdf<font class="kw">-></font>Cell<font class="kw">(</font>60<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Powered by FPDF.'</font><font class="kw">,</font>0<font class="kw">,</font>1<font class="kw">,</font><font class="str">'C'</font><font class="kw">);</font><br> |
---|
| 77 | </font> |
---|
| 78 | </code></NOBR></TD></TR></TABLE><P></P> |
---|
| 79 | Remark : the line break can also be done with <A HREF='../doc/ln.htm'>Ln()</A>. This method allows to specify |
---|
| 80 | in addition the height of the break. |
---|
| 81 | <BR> |
---|
| 82 | <BR> |
---|
| 83 | Finally, the document is closed and sent to the browser with <A HREF='../doc/output.htm'>Output()</A>. We could have saved |
---|
| 84 | it in a file by passing the desired file name. |
---|
| 85 | <BR> |
---|
| 86 | <BR> |
---|
| 87 | Caution: in case when the PDF is sent to the browser, nothing else must be output, not before |
---|
| 88 | nor after (the least space or carriage return matters). If you send some data before, you will |
---|
| 89 | get the error message: "Some data has already been output to browser, can't send PDF file". If |
---|
| 90 | you send after, your browser may display a blank page. |
---|
| 91 | </BODY> |
---|
| 92 | </HTML> |
---|