PDF ohne PWD in V1.4; FDPI hinzugefügt

This commit is contained in:
aschwarz
2023-08-24 12:52:17 +02:00
parent 2d73a1b10b
commit 3f9a0b1cc4
191 changed files with 19632 additions and 0 deletions

View File

@ -0,0 +1,10 @@
The year 1866 was marked by a bizarre development, an unexplained and downright inexplicable phenomenon that surely no one has forgotten. Without getting into those rumors that upset civilians in the seaports and deranged the public mind even far inland, it must be said that professional seamen were especially alarmed. Traders, shipowners, captains of vessels, skippers, and master mariners from Europe and America, naval officers from every country, and at their heels the various national governments on these two continents, were all extremely disturbed by the business.
In essence, over a period of time several ships had encountered "an enormous thing" at sea, a long spindle-shaped object, sometimes giving off a phosphorescent glow, infinitely bigger and faster than any whale.
The relevant data on this apparition, as recorded in various logbooks, agreed pretty closely as to the structure of the object or creature in question, its unprecedented speed of movement, its startling locomotive power, and the unique vitality with which it seemed to be gifted. If it was a cetacean, it exceeded in bulk any whale previously classified by science. No naturalist, neither Cuvier nor Lac<61>p<EFBFBD>de, neither Professor Dumeril nor Professor de Quatrefages, would have accepted the existence of such a monster sight unseen -- specifically, unseen by their own scientific eyes.
Striking an average of observations taken at different times -- rejecting those timid estimates that gave the object a length of 200 feet, and ignoring those exaggerated views that saw it as a mile wide and three long--you could still assert that this phenomenal creature greatly exceeded the dimensions of anything then known to ichthyologists, if it existed at all.
Now then, it did exist, this was an undeniable fact; and since the human mind dotes on objects of wonder, you can understand the worldwide excitement caused by this unearthly apparition. As for relegating it to the realm of fiction, that charge had to be dropped.
In essence, on July 20, 1866, the steamer Governor Higginson, from the Calcutta & Burnach Steam Navigation Co., encountered this moving mass five miles off the eastern shores of Australia. Captain Baker at first thought he was in the presence of an unknown reef; he was even about to fix its exact position when two waterspouts shot out of this inexplicable object and sprang hissing into the air some 150 feet. So, unless this reef was subject to the intermittent eruptions of a geyser, the Governor Higginson had fair and honest dealings with some aquatic mammal, until then unknown, that could spurt from its blowholes waterspouts mixed with air and steam.
Similar events were likewise observed in Pacific seas, on July 23 of the same year, by the Christopher Columbus from the West India & Pacific Steam Navigation Co. Consequently, this extraordinary cetacean could transfer itself from one locality to another with startling swiftness, since within an interval of just three days, the Governor Higginson and the Christopher Columbus had observed it at two positions on the charts separated by a distance of more than 700 nautical leagues.
Fifteen days later and 2,000 leagues farther, the Helvetia from the Compagnie Nationale and the Shannon from the Royal Mail line, running on opposite tacks in that part of the Atlantic lying between the United States and Europe, respectively signaled each other that the monster had been sighted in latitude 42 degrees 15' north and longitude 60 degrees 35' west of the meridian of Greenwich. From their simultaneous observations, they were able to estimate the mammal's minimum length at more than 350 English feet; this was because both the Shannon and the Helvetia were of smaller dimensions, although each measured 100 meters stem to stern. Now then, the biggest whales, those rorqual whales that frequent the waterways of the Aleutian Islands, have never exceeded a length of 56 meters--if they reach even that.
One after another, reports arrived that would profoundly affect public opinion: new observations taken by the transatlantic liner Pereire, the Inman line's Etna running afoul of the monster, an official report drawn up by officers on the French frigate Normandy, dead-earnest reckonings obtained by the general staff of Commodore Fitz-James aboard the Lord Clyde. In lighthearted countries, people joked about this phenomenon, but such serious, practical countries as England, America, and Germany were deeply concerned.
In every big city the monster was the latest rage; they sang about it in the coffee houses, they ridiculed it in the newspapers, they dramatized it in the theaters. The tabloids found it a fine opportunity for hatching all sorts of hoaxes. In those newspapers short of copy, you saw the reappearance of every gigantic imaginary creature, from "Moby Dick," that dreadful white whale from the High Arctic regions, to the stupendous kraken whose tentacles could entwine a 500-ton craft and drag it into the ocean depths. They even reprinted reports from ancient times: the views of Aristotle and Pliny accepting the existence of such monsters, then the Norwegian stories of Bishop Pontoppidan, the narratives of Paul Egede, and finally the reports of Captain Harrington -- whose good faith is above suspicion--in which he claims he saw, while aboard the Castilian in 1857, one of those enormous serpents that, until then, had frequented only the seas of France's old extremist newspaper, The Constitutionalist.

View File

@ -0,0 +1,23 @@
During the period in which these developments were occurring, I had returned from a scientific undertaking organized to explore the Nebraska badlands in the United States. In my capacity as Assistant Professor at the Paris Museum of Natural History, I had been attached to this expedition by the French government. After spending six months in Nebraska, I arrived in New York laden with valuable collections near the end of March. My departure for France was set for early May. In the meantime, then, I was busy classifying my mineralogical, botanical, and zoological treasures when that incident took place with the Scotia.
I was perfectly abreast of this question, which was the big news of the day, and how could I not have been? I had read and reread every American and European newspaper without being any farther along. This mystery puzzled me. Finding it impossible to form any views, I drifted from one extreme to the other. Something was out there, that much was certain, and any doubting Thomas was invited to place his finger on the Scotia's wound.
When I arrived in New York, the question was at the boiling point. The hypothesis of a drifting islet or an elusive reef, put forward by people not quite in their right minds, was completely eliminated. And indeed, unless this reef had an engine in its belly, how could it move about with such prodigious speed?
Also discredited was the idea of a floating hull or some other enormous wreckage, and again because of this speed of movement.
So only two possible solutions to the question were left, creating two very distinct groups of supporters: on one side, those favoring a monster of colossal strength; on the other, those favoring an "underwater boat" of tremendous motor power.
Now then, although the latter hypothesis was completely admissible, it couldn't stand up to inquiries conducted in both the New World and the Old. That a private individual had such a mechanism at his disposal was less than probable. Where and when had he built it, and how could he have built it in secret?
Only some government could own such an engine of destruction, and in these disaster-filled times, when men tax their ingenuity to build increasingly powerful aggressive weapons, it was possible that, unknown to the rest of the world, some nation could have been testing such a fearsome machine. The Chassepot rifle led to the torpedo, and the torpedo has led to this underwater battering ram, which in turn will lead to the world putting its foot down. At least I hope it will.
But this hypothesis of a war machine collapsed in the face of formal denials from the various governments. Since the public interest was at stake and transoceanic travel was suffering, the sincerity of these governments could not be doubted. Besides, how could the assembly of this underwater boat have escaped public notice? Keeping a secret under such circumstances would be difficult enough for an individual, and certainly impossible for a nation whose every move is under constant surveillance by rival powers.
So, after inquiries conducted in England, France, Russia, Prussia, Spain, Italy, America, and even Turkey, the hypothesis of an underwater Monitor was ultimately rejected.
After I arrived in New York, several people did me the honor of consulting me on the phenomenon in question. In France I had published a two-volume work, in quarto, entitled The Mysteries of the Great Ocean Depths. Well received in scholarly circles, this book had established me as a specialist in this pretty obscure field of natural history. My views were in demand. As long as I could deny the reality of the business, I confined myself to a flat "no comment." But soon, pinned to the wall, I had to explain myself straight out. And in this vein, "the honorable Pierre Aronnax, Professor at the Paris Museum," was summoned by The New York Herald to formulate his views no matter what.
I complied. Since I could no longer hold my tongue, I let it wag. I discussed the question in its every aspect, both political and scientific, and this is an excerpt from the well-padded article I published in the issue of April 30.
"Therefore," I wrote, "after examining these different hypotheses one by one, we are forced, every other supposition having been refuted, to accept the existence of an extremely powerful marine animal.
"The deepest parts of the ocean are totally unknown to us. No soundings have been able to reach them. What goes on in those distant depths? What creatures inhabit, or could inhabit, those regions twelve or fifteen miles beneath the surface of the water? What is the constitution of these animals? It's almost beyond conjecture.
"However, the solution to this problem submitted to me can take the form of a choice between two alternatives.
"Either we know every variety of creature populating our planet, or we do not.
"If we do not know every one of them, if nature still keeps ichthyological secrets from us, nothing is more admissible than to accept the existence of fish or cetaceans of new species or even new genera, animals with a basically 'cast-iron' constitution that inhabit strata beyond the reach of our soundings, and which some development or other, an urge or a whim if you prefer, can bring to the upper level of the ocean for long intervals.
"If, on the other hand, we do know every living species, we must look for the animal in question among those marine creatures already cataloged, and in this event I would be inclined to accept the existence of a giant narwhale.
"The common narwhale, or sea unicorn, often reaches a length of sixty feet. Increase its dimensions fivefold or even tenfold, then give this cetacean a strength in proportion to its size while enlarging its offensive weapons, and you have the animal we're looking for. It would have the proportions determined by the officers of the Shannon, the instrument needed to perforate the Scotia, and the power to pierce a steamer's hull.
"In essence, the narwhale is armed with a sort of ivory sword, or lance, as certain naturalists have expressed it. It's a king-sized tooth as hard as steel. Some of these teeth have been found buried in the bodies of baleen whales, which the narwhale attacks with invariable success. Others have been wrenched, not without difficulty, from the undersides of vessels that narwhales have pierced clean through, as a gimlet pierces a wine barrel. The museum at the Faculty of Medicine in Paris owns one of these tusks with a length of 2.25 meters and a width at its base of forty-eight centimeters!
"All right then! Imagine this weapon to be ten times stronger and the animal ten times more powerful, launch it at a speed of twenty miles per hour, multiply its mass times its velocity, and you get just the collision we need to cause the specified catastrophe.
"So, until information becomes more abundant, I plump for a sea unicorn of colossal dimensions, no longer armed with a mere lance but with an actual spur, like ironclad frigates or those warships called 'rams,' whose mass and motor power it would possess simultaneously.
"This inexplicable phenomenon is thus explained away--unless it's something else entirely, which, despite everything that has been sighted, studied, explored and experienced, is still possible!"

View File

@ -0,0 +1,94 @@
Copyright (c) 2011 by LatinoType Limitada (luciano@latinotype.com),
with Reserved Font Names "Cecivhe" and "Ceviche One"
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@ -0,0 +1,25 @@
<?php
$type = 'TrueType';
$name = 'CevicheOne-Regular';
$desc = array('Ascent'=>806,'Descent'=>-237,'CapHeight'=>425,'Flags'=>32,'FontBBox'=>'[-42 -237 1427 806]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>294);
$up = -75;
$ut = 50;
$cw = array(
chr(0)=>294,chr(1)=>294,chr(2)=>294,chr(3)=>294,chr(4)=>294,chr(5)=>294,chr(6)=>294,chr(7)=>294,chr(8)=>294,chr(9)=>294,chr(10)=>294,chr(11)=>294,chr(12)=>294,chr(13)=>294,chr(14)=>294,chr(15)=>294,chr(16)=>294,chr(17)=>294,chr(18)=>294,chr(19)=>294,chr(20)=>294,chr(21)=>294,
chr(22)=>294,chr(23)=>294,chr(24)=>294,chr(25)=>294,chr(26)=>294,chr(27)=>294,chr(28)=>294,chr(29)=>294,chr(30)=>294,chr(31)=>294,' '=>130,'!'=>254,'"'=>334,'#'=>496,'$'=>469,'%'=>765,'&'=>761,'\''=>148,'('=>268,')'=>269,'*'=>435,'+'=>442,
','=>235,'-'=>339,'.'=>233,'/'=>301,'0'=>512,'1'=>252,'2'=>501,'3'=>471,'4'=>537,'5'=>471,'6'=>501,'7'=>424,'8'=>506,'9'=>502,':'=>292,';'=>299,'<'=>463,'='=>483,'>'=>459,'?'=>453,'@'=>672,'A'=>511,
'B'=>573,'C'=>480,'D'=>541,'E'=>507,'F'=>490,'G'=>515,'H'=>517,'I'=>250,'J'=>270,'K'=>570,'L'=>368,'M'=>620,'N'=>548,'O'=>507,'P'=>540,'Q'=>532,'R'=>552,'S'=>490,'T'=>434,'U'=>527,'V'=>514,'W'=>670,
'X'=>541,'Y'=>497,'Z'=>499,'['=>288,'\\'=>472,']'=>288,'^'=>448,'_'=>350,'`'=>449,'a'=>446,'b'=>454,'c'=>394,'d'=>462,'e'=>404,'f'=>332,'g'=>458,'h'=>446,'i'=>234,'j'=>232,'k'=>457,'l'=>231,'m'=>659,
'n'=>450,'o'=>412,'p'=>436,'q'=>468,'r'=>389,'s'=>394,'t'=>318,'u'=>458,'v'=>421,'w'=>612,'x'=>450,'y'=>429,'z'=>423,'{'=>312,'|'=>231,'}'=>312,'~'=>504,chr(127)=>294,chr(128)=>586,chr(129)=>294,chr(130)=>176,chr(131)=>377,
chr(132)=>361,chr(133)=>761,chr(134)=>422,chr(135)=>425,chr(136)=>448,chr(137)=>1050,chr(138)=>490,chr(139)=>377,chr(140)=>787,chr(141)=>294,chr(142)=>499,chr(143)=>294,chr(144)=>294,chr(145)=>171,chr(146)=>148,chr(147)=>357,chr(148)=>334,chr(149)=>266,chr(150)=>444,chr(151)=>554,chr(152)=>416,chr(153)=>608,
chr(154)=>394,chr(155)=>378,chr(156)=>674,chr(157)=>294,chr(158)=>423,chr(159)=>497,chr(160)=>130,chr(161)=>253,chr(162)=>424,chr(163)=>510,chr(164)=>665,chr(165)=>551,chr(166)=>252,chr(167)=>413,chr(168)=>505,chr(169)=>675,chr(170)=>361,chr(171)=>668,chr(172)=>548,chr(173)=>440,chr(174)=>676,chr(175)=>413,
chr(176)=>278,chr(177)=>438,chr(178)=>328,chr(179)=>318,chr(180)=>449,chr(181)=>463,chr(182)=>535,chr(183)=>234,chr(184)=>535,chr(185)=>176,chr(186)=>322,chr(187)=>669,chr(188)=>761,chr(189)=>710,chr(190)=>904,chr(191)=>452,chr(192)=>511,chr(193)=>511,chr(194)=>514,chr(195)=>511,chr(196)=>511,chr(197)=>511,
chr(198)=>787,chr(199)=>480,chr(200)=>507,chr(201)=>507,chr(202)=>507,chr(203)=>507,chr(204)=>250,chr(205)=>250,chr(206)=>271,chr(207)=>272,chr(208)=>542,chr(209)=>548,chr(210)=>507,chr(211)=>507,chr(212)=>507,chr(213)=>507,chr(214)=>507,chr(215)=>496,chr(216)=>507,chr(217)=>527,chr(218)=>527,chr(219)=>526,
chr(220)=>527,chr(221)=>497,chr(222)=>522,chr(223)=>457,chr(224)=>446,chr(225)=>446,chr(226)=>446,chr(227)=>446,chr(228)=>446,chr(229)=>446,chr(230)=>635,chr(231)=>394,chr(232)=>404,chr(233)=>404,chr(234)=>412,chr(235)=>401,chr(236)=>235,chr(237)=>235,chr(238)=>256,chr(239)=>249,chr(240)=>475,chr(241)=>450,
chr(242)=>412,chr(243)=>412,chr(244)=>412,chr(245)=>413,chr(246)=>412,chr(247)=>444,chr(248)=>412,chr(249)=>458,chr(250)=>458,chr(251)=>458,chr(252)=>458,chr(253)=>429,chr(254)=>452,chr(255)=>429);
$enc = 'cp1252';
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
$file = 'CevicheOne-Regular.z';
$originalsize = 25916;
$subsetted = true;
?>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,15 @@
Austria;Vienna;83859;8075
Belgium;Brussels;30518;10192
Denmark;Copenhagen;43094;5295
Finland;Helsinki;304529;5147
France;Paris;543965;58728
Germany;Berlin;357022;82057
Greece;Athens;131625;10511
Ireland;Dublin;70723;3694
Italy;Roma;301316;57563
Luxembourg;Luxembourg;2586;424
Netherlands;Amsterdam;41526;15654
Portugal;Lisbon;91906;9957
Spain;Madrid;504790;39348
Sweden;Stockholm;410934;8839
United Kingdom;London;243820;58862

View File

@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tutorials</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Tutorials</h1>
<ul style="list-style-type:none; margin-left:0; padding-left:0">
<li><a href="tuto1.htm">Tutorial 1</a>: Minimal example</li>
<li><a href="tuto2.htm">Tutorial 2</a>: Header, footer, page break and image</li>
<li><a href="tuto3.htm">Tutorial 3</a>: Line breaks and colors</li>
<li><a href="tuto4.htm">Tutorial 4</a>: Multi-columns</li>
<li><a href="tuto5.htm">Tutorial 5</a>: Tables</li>
<li><a href="tuto6.htm">Tutorial 6</a>: Links and flowing text</li>
<li><a href="tuto7.htm">Tutorial 7</a>: Adding new fonts and encodings</li>
</ul>
</body>
</html>

BIN
fpdf186/tutorial/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,6 @@
<?php
// Generation of font definition file for tutorial 7
require('../makefont/makefont.php');
MakeFont('CevicheOne-Regular.ttf', 'cp1252');
?>

View File

@ -0,0 +1,76 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Minimal example</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Minimal example</h1>
Let's start with the classic example:
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
</span>$pdf <span class="kw">= new </span>FPDF<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</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">);
</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">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto1.php' target='_blank' class='demo'>[Run]</a></p>
After including the library file, we create an FPDF object.
The <a href='../doc/__construct.htm'>constructor</a> is used here with the default values: pages are in A4 portrait and
the unit of measure is millimeter. It could have been specified explicitly with:
<div class="source">
<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">);
</span></code></pre>
</div>
It's possible to use landscape (<code>L</code>), other page sizes (such as <code>Letter</code> and
<code>Legal</code>) and units (<code>pt</code>, <code>cm</code>, <code>in</code>).
<br>
<br>
There's no page at the moment, so we have to add one with <a href='../doc/addpage.htm'>AddPage()</a>. The origin
is at the upper-left corner and the current position is by default set at 1 cm from the
borders; the margins can be changed with <a href='../doc/setmargins.htm'>SetMargins()</a>.
<br>
<br>
Before we can print text, it's mandatory to select a font with <a href='../doc/setfont.htm'>SetFont()</a>.
We choose Arial bold 16:
<div class="source">
<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">);
</span></code></pre>
</div>
We could have specified italics with I, underlined with U or a regular font with an empty string
(or any combination). Note that the font size is given in points, not millimeters (or another user
unit); it's the only exception. The other standard fonts are Times, Courier, Symbol and ZapfDingbats.
<br>
<br>
We can now print a cell with <a href='../doc/cell.htm'>Cell()</a>. A cell is a rectangular area, possibly framed,
which contains a line of text. It is output at the current position. We specify its dimensions,
its text (centered or aligned), if borders should be drawn, and where the current position
moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:
<div class="source">
<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">);
</span></code></pre>
</div>
To add a new cell next to it with centered text and go to the next line, we would do:
<div class="source">
<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">);
</span></code></pre>
</div>
Remark: the line break can also be done with <a href='../doc/ln.htm'>Ln()</a>. This method additionnaly allows to specify
the height of the break.
<br>
<br>
Finally, the document is closed and sent to the browser with <a href='../doc/output.htm'>Output()</a>. We could have saved
it to a file by passing the appropriate parameters.
<br>
<br>
<strong>Caution:</strong> in case when the PDF is sent to the browser, nothing else must be output by the
script, neither before nor after (no HTML, not even a space or a carriage return). If you send something
before, you will get the error message: "Some data has already been output, can't send PDF file". If you
send something after, the document might not display.
</body>
</html>

View File

@ -0,0 +1,9 @@
<?php
require('../fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

View File

@ -0,0 +1,80 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Header, footer, page break and image</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Header, footer, page break and image</h1>
Here's a two page example with header, footer and logo:
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
class </span>PDF <span class="kw">extends </span>FPDF
<span class="kw">{
</span><span class="cmt">// Page header
</span><span class="kw">function </span>Header<span class="kw">()
{
</span><span class="cmt">// Logo
</span>$<span class="kw">this-&gt;</span>Image<span class="kw">(</span><span class="str">'logo.png'</span><span class="kw">,</span>10<span class="kw">,</span>6<span class="kw">,</span>30<span class="kw">);
</span><span class="cmt">// Arial bold 15
</span>$<span class="kw">this-&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>15<span class="kw">);
</span><span class="cmt">// Move to the right
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>80<span class="kw">);
</span><span class="cmt">// Title
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>30<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Title'</span><span class="kw">,</span>1<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
</span><span class="cmt">// Line break
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>20<span class="kw">);
}
</span><span class="cmt">// Page footer
</span><span class="kw">function </span>Footer<span class="kw">()
{
</span><span class="cmt">// Position at 1.5 cm from bottom
</span>$<span class="kw">this-&gt;</span>SetY<span class="kw">(-</span>15<span class="kw">);
</span><span class="cmt">// Arial italic 8
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">'I'</span><span class="kw">,</span>8<span class="kw">);
</span><span class="cmt">// Page number
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Page '</span><span class="kw">.</span>$<span class="kw">this-&gt;</span>PageNo<span class="kw">().</span><span class="str">'/{nb}'</span><span class="kw">,</span>0<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
}
}
</span><span class="cmt">// Instanciation of inherited class
</span>$pdf <span class="kw">= new </span>PDF<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>AliasNbPages<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Times'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>12<span class="kw">);
for(</span>$i<span class="kw">=</span>1<span class="kw">;</span>$i<span class="kw">&lt;=</span>40<span class="kw">;</span>$i<span class="kw">++)
</span>$pdf<span class="kw">-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Printing line number '</span><span class="kw">.</span>$i<span class="kw">,</span>0<span class="kw">,</span>1<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto2.php' target='_blank' class='demo'>[Run]</a></p>
This example makes use of the <a href='../doc/header.htm'>Header()</a> and <a href='../doc/footer.htm'>Footer()</a> methods to process page headers and
footers. They are called automatically. They already exist in the FPDF class but do nothing,
therefore we have to extend the class and override them.
<br>
<br>
The logo is printed with the <a href='../doc/image.htm'>Image()</a> method by specifying its upper-left corner and
its width. The height is calculated automatically to respect the image proportions.
<br>
<br>
To print the page number, a null value is passed as the cell width. It means that the cell
should extend up to the right margin of the page; this is handy to center text. The current page
number is returned by the <a href='../doc/pageno.htm'>PageNo()</a> method; as for the total number of pages, it's obtained
via the special value <code>{nb}</code> which is substituted when the document is finished
(provided you first called <a href='../doc/aliasnbpages.htm'>AliasNbPages()</a>).
<br>
Note the use of the <a href='../doc/sety.htm'>SetY()</a> method which allows to set position at an absolute location in
the page, starting from the top or the bottom.
<br>
<br>
Another interesting feature is used here: the automatic page breaking. As soon as a cell would
cross a limit in the page (at 2 centimeters from the bottom by default), a break is issued
and the font restored. Although the header and footer select their own font (Arial), the body
continues with Times. This mechanism of automatic restoration also applies to colors and line
width. The limit which triggers page breaks can be set with <a href='../doc/setautopagebreak.htm'>SetAutoPageBreak()</a>.
</body>
</html>

View File

@ -0,0 +1,41 @@
<?php
require('../fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('logo.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'Title',1,0,'C');
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
?>

115
fpdf186/tutorial/tuto3.htm Normal file
View File

@ -0,0 +1,115 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Line breaks and colors</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Line breaks and colors</h1>
Let's continue with an example which prints justified paragraphs. It also illustrates the use
of colors.
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
class </span>PDF <span class="kw">extends </span>FPDF
<span class="kw">{
function </span>Header<span class="kw">()
{
global </span>$title<span class="kw">;
</span><span class="cmt">// Arial bold 15
</span>$<span class="kw">this-&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>15<span class="kw">);
</span><span class="cmt">// Calculate width of title and position
</span>$w <span class="kw">= </span>$<span class="kw">this-&gt;</span>GetStringWidth<span class="kw">(</span>$title<span class="kw">)+</span>6<span class="kw">;
</span>$<span class="kw">this-&gt;</span>SetX<span class="kw">((</span>210<span class="kw">-</span>$w<span class="kw">)/</span>2<span class="kw">);
</span><span class="cmt">// Colors of frame, background and text
</span>$<span class="kw">this-&gt;</span>SetDrawColor<span class="kw">(</span>0<span class="kw">,</span>80<span class="kw">,</span>180<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>230<span class="kw">,</span>230<span class="kw">,</span>0<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>220<span class="kw">,</span>50<span class="kw">,</span>50<span class="kw">);
</span><span class="cmt">// Thickness of frame (1 mm)
</span>$<span class="kw">this-&gt;</span>SetLineWidth<span class="kw">(</span>1<span class="kw">);
</span><span class="cmt">// Title
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">,</span>9<span class="kw">,</span>$title<span class="kw">,</span>1<span class="kw">,</span>1<span class="kw">,</span><span class="str">'C'</span><span class="kw">,</span>true<span class="kw">);
</span><span class="cmt">// Line break
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>10<span class="kw">);
}
function </span>Footer<span class="kw">()
{
</span><span class="cmt">// Position at 1.5 cm from bottom
</span>$<span class="kw">this-&gt;</span>SetY<span class="kw">(-</span>15<span class="kw">);
</span><span class="cmt">// Arial italic 8
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">'I'</span><span class="kw">,</span>8<span class="kw">);
</span><span class="cmt">// Text color in gray
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>128<span class="kw">);
</span><span class="cmt">// Page number
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Page '</span><span class="kw">.</span>$<span class="kw">this-&gt;</span>PageNo<span class="kw">(),</span>0<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
}
function </span>ChapterTitle<span class="kw">(</span>$num<span class="kw">, </span>$label<span class="kw">)
{
</span><span class="cmt">// Arial 12
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>12<span class="kw">);
</span><span class="cmt">// Background color
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>200<span class="kw">,</span>220<span class="kw">,</span>255<span class="kw">);
</span><span class="cmt">// Title
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>6<span class="kw">,</span><span class="str">"Chapter </span>$num<span class="str"> : </span>$label<span class="str">"</span><span class="kw">,</span>0<span class="kw">,</span>1<span class="kw">,</span><span class="str">'L'</span><span class="kw">,</span>true<span class="kw">);
</span><span class="cmt">// Line break
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>4<span class="kw">);
}
function </span>ChapterBody<span class="kw">(</span>$file<span class="kw">)
{
</span><span class="cmt">// Read text file
</span>$txt <span class="kw">= </span>file_get_contents<span class="kw">(</span>$file<span class="kw">);
</span><span class="cmt">// Times 12
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Times'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>12<span class="kw">);
</span><span class="cmt">// Output justified text
</span>$<span class="kw">this-&gt;</span>MultiCell<span class="kw">(</span>0<span class="kw">,</span>5<span class="kw">,</span>$txt<span class="kw">);
</span><span class="cmt">// Line break
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span><span class="cmt">// Mention in italics
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">,</span><span class="str">'I'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>5<span class="kw">,</span><span class="str">'(end of excerpt)'</span><span class="kw">);
}
function </span>PrintChapter<span class="kw">(</span>$num<span class="kw">, </span>$title<span class="kw">, </span>$file<span class="kw">)
{
</span>$<span class="kw">this-&gt;</span>AddPage<span class="kw">();
</span>$<span class="kw">this-&gt;</span>ChapterTitle<span class="kw">(</span>$num<span class="kw">,</span>$title<span class="kw">);
</span>$<span class="kw">this-&gt;</span>ChapterBody<span class="kw">(</span>$file<span class="kw">);
}
}
</span>$pdf <span class="kw">= new </span>PDF<span class="kw">();
</span>$title <span class="kw">= </span><span class="str">'20000 Leagues Under the Seas'</span><span class="kw">;
</span>$pdf<span class="kw">-&gt;</span>SetTitle<span class="kw">(</span>$title<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetAuthor<span class="kw">(</span><span class="str">'Jules Verne'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>PrintChapter<span class="kw">(</span>1<span class="kw">,</span><span class="str">'A RUNAWAY REEF'</span><span class="kw">,</span><span class="str">'20k_c1.txt'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>PrintChapter<span class="kw">(</span>2<span class="kw">,</span><span class="str">'THE PROS AND CONS'</span><span class="kw">,</span><span class="str">'20k_c2.txt'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto3.php' target='_blank' class='demo'>[Run]</a></p>
The <a href='../doc/getstringwidth.htm'>GetStringWidth()</a> method allows to determine the length of a string in the current font,
which is used here to calculate the position and the width of the frame surrounding the title.
Then colors are set (via <a href='../doc/setdrawcolor.htm'>SetDrawColor()</a>, <a href='../doc/setfillcolor.htm'>SetFillColor()</a> and <a href='../doc/settextcolor.htm'>SetTextColor()</a>) and the
thickness of the line is set to 1 mm (instead of 0.2 by default) with <a href='../doc/setlinewidth.htm'>SetLineWidth()</a>. Finally,
we output the cell (the last parameter <code>true</code> indicates that the background must
be filled).
<br>
<br>
The method used to print the paragraphs is <a href='../doc/multicell.htm'>MultiCell()</a>. Each time a line reaches the
right extremity of the cell or a carriage return character is met, a line break is issued
and a new cell automatically created under the current one. Text is justified by default.
<br>
<br>
Two document properties are defined: the title (<a href='../doc/settitle.htm'>SetTitle()</a>) and the author (<a href='../doc/setauthor.htm'>SetAuthor()</a>).
There are several ways to view them in Adobe Reader. The first one is to open the file directly with
the reader, go to the File menu and choose the Properties option. The second one, also available from
the plug-in, is to right-click and select Document Properties. The third method is to type the Ctrl+D
key combination.
</body>
</html>

View File

@ -0,0 +1,81 @@
<?php
require('../fpdf.php');
class PDF extends FPDF
{
function Header()
{
global $title;
// Arial bold 15
$this->SetFont('Arial','B',15);
// Calculate width of title and position
$w = $this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
// Colors of frame, background and text
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
// Thickness of frame (1 mm)
$this->SetLineWidth(1);
// Title
$this->Cell($w,9,$title,1,1,'C',true);
// Line break
$this->Ln(10);
}
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Text color in gray
$this->SetTextColor(128);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function ChapterTitle($num, $label)
{
// Arial 12
$this->SetFont('Arial','',12);
// Background color
$this->SetFillColor(200,220,255);
// Title
$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
// Line break
$this->Ln(4);
}
function ChapterBody($file)
{
// Read text file
$txt = file_get_contents($file);
// Times 12
$this->SetFont('Times','',12);
// Output justified text
$this->MultiCell(0,5,$txt);
// Line break
$this->Ln();
// Mention in italics
$this->SetFont('','I');
$this->Cell(0,5,'(end of excerpt)');
}
function PrintChapter($num, $title, $file)
{
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
$pdf->Output();
?>

132
fpdf186/tutorial/tuto4.htm Normal file
View File

@ -0,0 +1,132 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Multi-columns</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Multi-columns</h1>
This example is a variant of the previous one showing how to lay the text across multiple
columns.
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
class </span>PDF <span class="kw">extends </span>FPDF
<span class="kw">{
protected </span>$col <span class="kw">= </span>0<span class="kw">; </span><span class="cmt">// Current column
</span><span class="kw">protected </span>$y0<span class="kw">; </span><span class="cmt">// Ordinate of column start
</span><span class="kw">function </span>Header<span class="kw">()
{
</span><span class="cmt">// Page header
</span><span class="kw">global </span>$title<span class="kw">;
</span>$<span class="kw">this-&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>15<span class="kw">);
</span>$w <span class="kw">= </span>$<span class="kw">this-&gt;</span>GetStringWidth<span class="kw">(</span>$title<span class="kw">)+</span>6<span class="kw">;
</span>$<span class="kw">this-&gt;</span>SetX<span class="kw">((</span>210<span class="kw">-</span>$w<span class="kw">)/</span>2<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetDrawColor<span class="kw">(</span>0<span class="kw">,</span>80<span class="kw">,</span>180<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>230<span class="kw">,</span>230<span class="kw">,</span>0<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>220<span class="kw">,</span>50<span class="kw">,</span>50<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetLineWidth<span class="kw">(</span>1<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">,</span>9<span class="kw">,</span>$title<span class="kw">,</span>1<span class="kw">,</span>1<span class="kw">,</span><span class="str">'C'</span><span class="kw">,</span>true<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>10<span class="kw">);
</span><span class="cmt">// Save ordinate
</span>$<span class="kw">this-&gt;</span>y0 <span class="kw">= </span>$<span class="kw">this-&gt;</span>GetY<span class="kw">();
}
function </span>Footer<span class="kw">()
{
</span><span class="cmt">// Page footer
</span>$<span class="kw">this-&gt;</span>SetY<span class="kw">(-</span>15<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">'I'</span><span class="kw">,</span>8<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>128<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>10<span class="kw">,</span><span class="str">'Page '</span><span class="kw">.</span>$<span class="kw">this-&gt;</span>PageNo<span class="kw">(),</span>0<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
}
function </span>SetCol<span class="kw">(</span>$col<span class="kw">)
{
</span><span class="cmt">// Set position at a given column
</span>$<span class="kw">this-&gt;</span>col <span class="kw">= </span>$col<span class="kw">;
</span>$x <span class="kw">= </span>10<span class="kw">+</span>$col<span class="kw">*</span>65<span class="kw">;
</span>$<span class="kw">this-&gt;</span>SetLeftMargin<span class="kw">(</span>$x<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetX<span class="kw">(</span>$x<span class="kw">);
}
function </span>AcceptPageBreak<span class="kw">()
{
</span><span class="cmt">// Method accepting or not automatic page break
</span><span class="kw">if(</span>$<span class="kw">this-&gt;</span>col<span class="kw">&lt;</span>2<span class="kw">)
{
</span><span class="cmt">// Go to next column
</span>$<span class="kw">this-&gt;</span>SetCol<span class="kw">(</span>$<span class="kw">this-&gt;</span>col<span class="kw">+</span>1<span class="kw">);
</span><span class="cmt">// Set ordinate to top
</span>$<span class="kw">this-&gt;</span>SetY<span class="kw">(</span>$<span class="kw">this-&gt;</span>y0<span class="kw">);
</span><span class="cmt">// Keep on page
</span><span class="kw">return </span>false<span class="kw">;
}
else
{
</span><span class="cmt">// Go back to first column
</span>$<span class="kw">this-&gt;</span>SetCol<span class="kw">(</span>0<span class="kw">);
</span><span class="cmt">// Page break
</span><span class="kw">return </span>true<span class="kw">;
}
}
function </span>ChapterTitle<span class="kw">(</span>$num<span class="kw">, </span>$label<span class="kw">)
{
</span><span class="cmt">// Title
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>12<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>200<span class="kw">,</span>220<span class="kw">,</span>255<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>6<span class="kw">,</span><span class="str">"Chapter </span>$num<span class="str"> : </span>$label<span class="str">"</span><span class="kw">,</span>0<span class="kw">,</span>1<span class="kw">,</span><span class="str">'L'</span><span class="kw">,</span>true<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>4<span class="kw">);
</span><span class="cmt">// Save ordinate
</span>$<span class="kw">this-&gt;</span>y0 <span class="kw">= </span>$<span class="kw">this-&gt;</span>GetY<span class="kw">();
}
function </span>ChapterBody<span class="kw">(</span>$file<span class="kw">)
{
</span><span class="cmt">// Read text file
</span>$txt <span class="kw">= </span>file_get_contents<span class="kw">(</span>$file<span class="kw">);
</span><span class="cmt">// Font
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Times'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>12<span class="kw">);
</span><span class="cmt">// Output text in a 6 cm width column
</span>$<span class="kw">this-&gt;</span>MultiCell<span class="kw">(</span>60<span class="kw">,</span>5<span class="kw">,</span>$txt<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span><span class="cmt">// Mention
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">,</span><span class="str">'I'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>0<span class="kw">,</span>5<span class="kw">,</span><span class="str">'(end of excerpt)'</span><span class="kw">);
</span><span class="cmt">// Go back to first column
</span>$<span class="kw">this-&gt;</span>SetCol<span class="kw">(</span>0<span class="kw">);
}
function </span>PrintChapter<span class="kw">(</span>$num<span class="kw">, </span>$title<span class="kw">, </span>$file<span class="kw">)
{
</span><span class="cmt">// Add chapter
</span>$<span class="kw">this-&gt;</span>AddPage<span class="kw">();
</span>$<span class="kw">this-&gt;</span>ChapterTitle<span class="kw">(</span>$num<span class="kw">,</span>$title<span class="kw">);
</span>$<span class="kw">this-&gt;</span>ChapterBody<span class="kw">(</span>$file<span class="kw">);
}
}
</span>$pdf <span class="kw">= new </span>PDF<span class="kw">();
</span>$title <span class="kw">= </span><span class="str">'20000 Leagues Under the Seas'</span><span class="kw">;
</span>$pdf<span class="kw">-&gt;</span>SetTitle<span class="kw">(</span>$title<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetAuthor<span class="kw">(</span><span class="str">'Jules Verne'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>PrintChapter<span class="kw">(</span>1<span class="kw">,</span><span class="str">'A RUNAWAY REEF'</span><span class="kw">,</span><span class="str">'20k_c1.txt'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>PrintChapter<span class="kw">(</span>2<span class="kw">,</span><span class="str">'THE PROS AND CONS'</span><span class="kw">,</span><span class="str">'20k_c2.txt'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto4.php' target='_blank' class='demo'>[Run]</a></p>
The key method used is <a href='../doc/acceptpagebreak.htm'>AcceptPageBreak()</a>. It allows to accept or not an automatic page
break. By refusing it and altering the margin and current position, the desired column layout
is achieved.
<br>
For the rest, not many changes; two properties have been added to the class to save the current
column number and the position where columns begin, and the MultiCell() call specifies a
6 centimeter width.
</body>
</html>

109
fpdf186/tutorial/tuto4.php Normal file
View File

@ -0,0 +1,109 @@
<?php
require('../fpdf.php');
class PDF extends FPDF
{
protected $col = 0; // Current column
protected $y0; // Ordinate of column start
function Header()
{
// Page header
global $title;
$this->SetFont('Arial','B',15);
$w = $this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
$this->SetLineWidth(1);
$this->Cell($w,9,$title,1,1,'C',true);
$this->Ln(10);
// Save ordinate
$this->y0 = $this->GetY();
}
function Footer()
{
// Page footer
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
function SetCol($col)
{
// Set position at a given column
$this->col = $col;
$x = 10+$col*65;
$this->SetLeftMargin($x);
$this->SetX($x);
}
function AcceptPageBreak()
{
// Method accepting or not automatic page break
if($this->col<2)
{
// Go to next column
$this->SetCol($this->col+1);
// Set ordinate to top
$this->SetY($this->y0);
// Keep on page
return false;
}
else
{
// Go back to first column
$this->SetCol(0);
// Page break
return true;
}
}
function ChapterTitle($num, $label)
{
// Title
$this->SetFont('Arial','',12);
$this->SetFillColor(200,220,255);
$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
$this->Ln(4);
// Save ordinate
$this->y0 = $this->GetY();
}
function ChapterBody($file)
{
// Read text file
$txt = file_get_contents($file);
// Font
$this->SetFont('Times','',12);
// Output text in a 6 cm width column
$this->MultiCell(60,5,$txt);
$this->Ln();
// Mention
$this->SetFont('','I');
$this->Cell(0,5,'(end of excerpt)');
// Go back to first column
$this->SetCol(0);
}
function PrintChapter($num, $title, $file)
{
// Add chapter
$this->AddPage();
$this->ChapterTitle($num,$title);
$this->ChapterBody($file);
}
}
$pdf = new PDF();
$title = '20000 Leagues Under the Seas';
$pdf->SetTitle($title);
$pdf->SetAuthor('Jules Verne');
$pdf->PrintChapter(1,'A RUNAWAY REEF','20k_c1.txt');
$pdf->PrintChapter(2,'THE PROS AND CONS','20k_c2.txt');
$pdf->Output();
?>

134
fpdf186/tutorial/tuto5.htm Normal file
View File

@ -0,0 +1,134 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tables</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Tables</h1>
This tutorial shows different ways to make tables.
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
class </span>PDF <span class="kw">extends </span>FPDF
<span class="kw">{
</span><span class="cmt">// Load data
</span><span class="kw">function </span>LoadData<span class="kw">(</span>$file<span class="kw">)
{
</span><span class="cmt">// Read file lines
</span>$lines <span class="kw">= </span>file<span class="kw">(</span>$file<span class="kw">);
</span>$data <span class="kw">= array();
foreach(</span>$lines <span class="kw">as </span>$line<span class="kw">)
</span>$data<span class="kw">[] = </span>explode<span class="kw">(</span><span class="str">';'</span><span class="kw">,</span>trim<span class="kw">(</span>$line<span class="kw">));
return </span>$data<span class="kw">;
}
</span><span class="cmt">// Simple table
</span><span class="kw">function </span>BasicTable<span class="kw">(</span>$header<span class="kw">, </span>$data<span class="kw">)
{
</span><span class="cmt">// Header
</span><span class="kw">foreach(</span>$header <span class="kw">as </span>$col<span class="kw">)
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>40<span class="kw">,</span>7<span class="kw">,</span>$col<span class="kw">,</span>1<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span><span class="cmt">// Data
</span><span class="kw">foreach(</span>$data <span class="kw">as </span>$row<span class="kw">)
{
foreach(</span>$row <span class="kw">as </span>$col<span class="kw">)
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>40<span class="kw">,</span>6<span class="kw">,</span>$col<span class="kw">,</span>1<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
}
}
</span><span class="cmt">// Better table
</span><span class="kw">function </span>ImprovedTable<span class="kw">(</span>$header<span class="kw">, </span>$data<span class="kw">)
{
</span><span class="cmt">// Column widths
</span>$w <span class="kw">= array(</span>40<span class="kw">, </span>35<span class="kw">, </span>40<span class="kw">, </span>45<span class="kw">);
</span><span class="cmt">// Header
</span><span class="kw">for(</span>$i<span class="kw">=</span>0<span class="kw">;</span>$i<span class="kw">&lt;</span>count<span class="kw">(</span>$header<span class="kw">);</span>$i<span class="kw">++)
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>$i<span class="kw">],</span>7<span class="kw">,</span>$header<span class="kw">[</span>$i<span class="kw">],</span>1<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span><span class="cmt">// Data
</span><span class="kw">foreach(</span>$data <span class="kw">as </span>$row<span class="kw">)
{
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>0<span class="kw">],</span>6<span class="kw">,</span>$row<span class="kw">[</span>0<span class="kw">],</span><span class="str">'LR'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>1<span class="kw">],</span>6<span class="kw">,</span>$row<span class="kw">[</span>1<span class="kw">],</span><span class="str">'LR'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>2<span class="kw">],</span>6<span class="kw">,</span>number_format<span class="kw">(</span>$row<span class="kw">[</span>2<span class="kw">]),</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'R'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>3<span class="kw">],</span>6<span class="kw">,</span>number_format<span class="kw">(</span>$row<span class="kw">[</span>3<span class="kw">]),</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'R'</span><span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
}
</span><span class="cmt">// Closing line
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>array_sum<span class="kw">(</span>$w<span class="kw">),</span>0<span class="kw">,</span><span class="str">''</span><span class="kw">,</span><span class="str">'T'</span><span class="kw">);
}
</span><span class="cmt">// Colored table
</span><span class="kw">function </span>FancyTable<span class="kw">(</span>$header<span class="kw">, </span>$data<span class="kw">)
{
</span><span class="cmt">// Colors, line width and bold font
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>255<span class="kw">,</span>0<span class="kw">,</span>0<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>255<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetDrawColor<span class="kw">(</span>128<span class="kw">,</span>0<span class="kw">,</span>0<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetLineWidth<span class="kw">(</span>.3<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">,</span><span class="str">'B'</span><span class="kw">);
</span><span class="cmt">// Header
</span>$w <span class="kw">= array(</span>40<span class="kw">, </span>35<span class="kw">, </span>40<span class="kw">, </span>45<span class="kw">);
for(</span>$i<span class="kw">=</span>0<span class="kw">;</span>$i<span class="kw">&lt;</span>count<span class="kw">(</span>$header<span class="kw">);</span>$i<span class="kw">++)
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>$i<span class="kw">],</span>7<span class="kw">,</span>$header<span class="kw">[</span>$i<span class="kw">],</span>1<span class="kw">,</span>0<span class="kw">,</span><span class="str">'C'</span><span class="kw">,</span>true<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span><span class="cmt">// Color and font restoration
</span>$<span class="kw">this-&gt;</span>SetFillColor<span class="kw">(</span>224<span class="kw">,</span>235<span class="kw">,</span>255<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>0<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">);
</span><span class="cmt">// Data
</span>$fill <span class="kw">= </span>false<span class="kw">;
foreach(</span>$data <span class="kw">as </span>$row<span class="kw">)
{
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>0<span class="kw">],</span>6<span class="kw">,</span>$row<span class="kw">[</span>0<span class="kw">],</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'L'</span><span class="kw">,</span>$fill<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>1<span class="kw">],</span>6<span class="kw">,</span>$row<span class="kw">[</span>1<span class="kw">],</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'L'</span><span class="kw">,</span>$fill<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>2<span class="kw">],</span>6<span class="kw">,</span>number_format<span class="kw">(</span>$row<span class="kw">[</span>2<span class="kw">]),</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'R'</span><span class="kw">,</span>$fill<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>$w<span class="kw">[</span>3<span class="kw">],</span>6<span class="kw">,</span>number_format<span class="kw">(</span>$row<span class="kw">[</span>3<span class="kw">]),</span><span class="str">'LR'</span><span class="kw">,</span>0<span class="kw">,</span><span class="str">'R'</span><span class="kw">,</span>$fill<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">();
</span>$fill <span class="kw">= !</span>$fill<span class="kw">;
}
</span><span class="cmt">// Closing line
</span>$<span class="kw">this-&gt;</span>Cell<span class="kw">(</span>array_sum<span class="kw">(</span>$w<span class="kw">),</span>0<span class="kw">,</span><span class="str">''</span><span class="kw">,</span><span class="str">'T'</span><span class="kw">);
}
}
</span>$pdf <span class="kw">= new </span>PDF<span class="kw">();
</span><span class="cmt">// Column headings
</span>$header <span class="kw">= array(</span><span class="str">'Country'</span><span class="kw">, </span><span class="str">'Capital'</span><span class="kw">, </span><span class="str">'Area (sq km)'</span><span class="kw">, </span><span class="str">'Pop. (thousands)'</span><span class="kw">);
</span><span class="cmt">// Data loading
</span>$data <span class="kw">= </span>$pdf<span class="kw">-&gt;</span>LoadData<span class="kw">(</span><span class="str">'countries.txt'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>14<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>BasicTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>ImprovedTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>FancyTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto5.php' target='_blank' class='demo'>[Run]</a></p>
A table being just a collection of cells, it's natural to build one from them. The first
example is achieved in the most basic way possible: simple framed cells, all of the same size
and left aligned. The result is rudimentary but very quick to obtain.
<br>
<br>
The second table brings some improvements: each column has its own width, headings are centered,
and numbers right aligned. Moreover, horizontal lines have been removed. This is done by means
of the <code>border</code> parameter of the <a href='../doc/cell.htm'>Cell()</a> method, which specifies which sides of the
cell must be drawn. Here we want the left (<code>L</code>) and right (<code>R</code>) ones. It remains
the problem of the horizontal line to finish the table. There are two possibilities: either
check for the last line in the loop, in which case we use <code>LRB</code> for the <code>border</code>
parameter; or, as done here, add the line once the loop is over.
<br>
<br>
The third table is similar to the second one but uses colors. Fill, text and line colors are
simply specified. Alternate coloring for rows is obtained by using alternatively transparent
and filled cells.
</body>
</html>

102
fpdf186/tutorial/tuto5.php Normal file
View File

@ -0,0 +1,102 @@
<?php
require('../fpdf.php');
class PDF extends FPDF
{
// Load data
function LoadData($file)
{
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Better table
function ImprovedTable($header, $data)
{
// Column widths
$w = array(40, 35, 40, 45);
// Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Data
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
$this->Ln();
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf = new PDF();
// Column headings
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
// Data loading
$data = $pdf->LoadData('countries.txt');
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
$pdf->BasicTable($header,$data);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->AddPage();
$pdf->FancyTable($header,$data);
$pdf->Output();
?>

154
fpdf186/tutorial/tuto6.htm Normal file
View File

@ -0,0 +1,154 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Links and flowing text</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Links and flowing text</h1>
This tutorial explains how to insert links (internal and external) and shows a new text writing
mode. It also contains a basic HTML parser.
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
class </span>PDF <span class="kw">extends </span>FPDF
<span class="kw">{
protected </span>$B <span class="kw">= </span>0<span class="kw">;
protected </span>$I <span class="kw">= </span>0<span class="kw">;
protected </span>$U <span class="kw">= </span>0<span class="kw">;
protected </span>$HREF <span class="kw">= </span><span class="str">''</span><span class="kw">;
function </span>WriteHTML<span class="kw">(</span>$html<span class="kw">)
{
</span><span class="cmt">// HTML parser
</span>$html <span class="kw">= </span>str_replace<span class="kw">(</span><span class="str">"\n"</span><span class="kw">,</span><span class="str">' '</span><span class="kw">,</span>$html<span class="kw">);
</span>$a <span class="kw">= </span>preg_split<span class="kw">(</span><span class="str">'/&lt;(.*)&gt;/U'</span><span class="kw">,</span>$html<span class="kw">,-</span>1<span class="kw">,</span>PREG_SPLIT_DELIM_CAPTURE<span class="kw">);
foreach(</span>$a <span class="kw">as </span>$i<span class="kw">=&gt;</span>$e<span class="kw">)
{
if(</span>$i<span class="kw">%</span>2<span class="kw">==</span>0<span class="kw">)
{
</span><span class="cmt">// Text
</span><span class="kw">if(</span>$<span class="kw">this-&gt;</span>HREF<span class="kw">)
</span>$<span class="kw">this-&gt;</span>PutLink<span class="kw">(</span>$<span class="kw">this-&gt;</span>HREF<span class="kw">,</span>$e<span class="kw">);
else
</span>$<span class="kw">this-&gt;</span>Write<span class="kw">(</span>5<span class="kw">,</span>$e<span class="kw">);
}
else
{
</span><span class="cmt">// Tag
</span><span class="kw">if(</span>$e<span class="kw">[</span>0<span class="kw">]==</span><span class="str">'/'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>CloseTag<span class="kw">(</span>strtoupper<span class="kw">(</span>substr<span class="kw">(</span>$e<span class="kw">,</span>1<span class="kw">)));
else
{
</span><span class="cmt">// Extract attributes
</span>$a2 <span class="kw">= </span>explode<span class="kw">(</span><span class="str">' '</span><span class="kw">,</span>$e<span class="kw">);
</span>$tag <span class="kw">= </span>strtoupper<span class="kw">(</span>array_shift<span class="kw">(</span>$a2<span class="kw">));
</span>$attr <span class="kw">= array();
foreach(</span>$a2 <span class="kw">as </span>$v<span class="kw">)
{
if(</span>preg_match<span class="kw">(</span><span class="str">'/([^=]*)=["\']?([^"\']*)/'</span><span class="kw">,</span>$v<span class="kw">,</span>$a3<span class="kw">))
</span>$attr<span class="kw">[</span>strtoupper<span class="kw">(</span>$a3<span class="kw">[</span>1<span class="kw">])] = </span>$a3<span class="kw">[</span>2<span class="kw">];
}
</span>$<span class="kw">this-&gt;</span>OpenTag<span class="kw">(</span>$tag<span class="kw">,</span>$attr<span class="kw">);
}
}
}
}
function </span>OpenTag<span class="kw">(</span>$tag<span class="kw">, </span>$attr<span class="kw">)
{
</span><span class="cmt">// Opening tag
</span><span class="kw">if(</span>$tag<span class="kw">==</span><span class="str">'B' </span><span class="kw">|| </span>$tag<span class="kw">==</span><span class="str">'I' </span><span class="kw">|| </span>$tag<span class="kw">==</span><span class="str">'U'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>SetStyle<span class="kw">(</span>$tag<span class="kw">,</span>true<span class="kw">);
if(</span>$tag<span class="kw">==</span><span class="str">'A'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>HREF <span class="kw">= </span>$attr<span class="kw">[</span><span class="str">'HREF'</span><span class="kw">];
if(</span>$tag<span class="kw">==</span><span class="str">'BR'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>Ln<span class="kw">(</span>5<span class="kw">);
}
function </span>CloseTag<span class="kw">(</span>$tag<span class="kw">)
{
</span><span class="cmt">// Closing tag
</span><span class="kw">if(</span>$tag<span class="kw">==</span><span class="str">'B' </span><span class="kw">|| </span>$tag<span class="kw">==</span><span class="str">'I' </span><span class="kw">|| </span>$tag<span class="kw">==</span><span class="str">'U'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>SetStyle<span class="kw">(</span>$tag<span class="kw">,</span>false<span class="kw">);
if(</span>$tag<span class="kw">==</span><span class="str">'A'</span><span class="kw">)
</span>$<span class="kw">this-&gt;</span>HREF <span class="kw">= </span><span class="str">''</span><span class="kw">;
}
function </span>SetStyle<span class="kw">(</span>$tag<span class="kw">, </span>$enable<span class="kw">)
{
</span><span class="cmt">// Modify style and select corresponding font
</span>$<span class="kw">this-&gt;</span>$tag <span class="kw">+= (</span>$enable <span class="kw">? </span>1 <span class="kw">: -</span>1<span class="kw">);
</span>$style <span class="kw">= </span><span class="str">''</span><span class="kw">;
foreach(array(</span><span class="str">'B'</span><span class="kw">, </span><span class="str">'I'</span><span class="kw">, </span><span class="str">'U'</span><span class="kw">) as </span>$s<span class="kw">)
{
if(</span>$<span class="kw">this-&gt;</span>$s<span class="kw">&gt;</span>0<span class="kw">)
</span>$style <span class="kw">.= </span>$s<span class="kw">;
}
</span>$<span class="kw">this-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">,</span>$style<span class="kw">);
}
function </span>PutLink<span class="kw">(</span>$URL<span class="kw">, </span>$txt<span class="kw">)
{
</span><span class="cmt">// Put a hyperlink
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>0<span class="kw">,</span>0<span class="kw">,</span>255<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetStyle<span class="kw">(</span><span class="str">'U'</span><span class="kw">,</span>true<span class="kw">);
</span>$<span class="kw">this-&gt;</span>Write<span class="kw">(</span>5<span class="kw">,</span>$txt<span class="kw">,</span>$URL<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetStyle<span class="kw">(</span><span class="str">'U'</span><span class="kw">,</span>false<span class="kw">);
</span>$<span class="kw">this-&gt;</span>SetTextColor<span class="kw">(</span>0<span class="kw">);
}
}
</span>$html <span class="kw">= </span><span class="str">'You can now easily print text mixing different styles: &lt;b&gt;bold&lt;/b&gt;, &lt;i&gt;italic&lt;/i&gt;,
&lt;u&gt;underlined&lt;/u&gt;, or &lt;b&gt;&lt;i&gt;&lt;u&gt;all at once&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;!&lt;br&gt;&lt;br&gt;You can also insert links on
text, such as &lt;a href="http://www.fpdf.org"&gt;www.fpdf.org&lt;/a&gt;, or on an image: click on the logo.'</span><span class="kw">;
</span>$pdf <span class="kw">= new </span>PDF<span class="kw">();
</span><span class="cmt">// First page
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'Arial'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>20<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Write<span class="kw">(</span>5<span class="kw">,</span><span class="str">"To find out what's new in this tutorial, click "</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">,</span><span class="str">'U'</span><span class="kw">);
</span>$link <span class="kw">= </span>$pdf<span class="kw">-&gt;</span>AddLink<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>Write<span class="kw">(</span>5<span class="kw">,</span><span class="str">'here'</span><span class="kw">,</span>$link<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">);
</span><span class="cmt">// Second page
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>SetLink<span class="kw">(</span>$link<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Image<span class="kw">(</span><span class="str">'logo.png'</span><span class="kw">,</span>10<span class="kw">,</span>12<span class="kw">,</span>30<span class="kw">,</span>0<span class="kw">,</span><span class="str">''</span><span class="kw">,</span><span class="str">'http://www.fpdf.org'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetLeftMargin<span class="kw">(</span>45<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>SetFontSize<span class="kw">(</span>14<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>WriteHTML<span class="kw">(</span>$html<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto6.php' target='_blank' class='demo'>[Run]</a></p>
The new method to print text is <a href='../doc/write.htm'>Write()</a>. It's very close to <a href='../doc/multicell.htm'>MultiCell()</a>; the differences are:
<ul>
<li>The end of line is at the right margin and the next line begins at the left one</li>
<li>The current position moves at the end of the text</li>
</ul>
So it allows to write a chunk of text, alter the font style, then continue from the exact
place we left it. On the other hand, you cannot justify it.
<br>
<br>
The method is used on the first page to put a link pointing to the second one. The beginning of
the sentence is written in regular style, then we switch to underline and finish it. The link
is created with <a href='../doc/addlink.htm'>AddLink()</a>, which returns a link identifier. The identifier is
passed as third parameter of Write(). Once the second page is created, we use <a href='../doc/setlink.htm'>SetLink()</a> to
make the link point to the beginning of the current page.
<br>
<br>
Then we put an image with an external link on it. An external link is just a URL. It's passed as
last parameter of <a href='../doc/image.htm'>Image()</a>.
<br>
<br>
Finally, the left margin is moved after the image with <a href='../doc/setleftmargin.htm'>SetLeftMargin()</a> and some text in
HTML format is output. A very simple HTML parser is used for this, based on regular expressions.
Recognized tags are &lt;b&gt;, &lt;i&gt;, &lt;u&gt;, &lt;a&gt; and &lt;br&gt;; the others are
ignored. The parser also makes use of the Write() method. An external link is put the same way as
an internal one (third parameter of Write()). Note that <a href='../doc/cell.htm'>Cell()</a> also allows to put links.
</body>
</html>

113
fpdf186/tutorial/tuto6.php Normal file
View File

@ -0,0 +1,113 @@
<?php
require('../fpdf.php');
class PDF extends FPDF
{
protected $B = 0;
protected $I = 0;
protected $U = 0;
protected $HREF = '';
function WriteHTML($html)
{
// HTML parser
$html = str_replace("\n",' ',$html);
$a = preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($a as $i=>$e)
{
if($i%2==0)
{
// Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
// Tag
if($e[0]=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
// Extract attributes
$a2 = explode(' ',$e);
$tag = strtoupper(array_shift($a2));
$attr = array();
foreach($a2 as $v)
{
if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
$attr[strtoupper($a3[1])] = $a3[2];
}
$this->OpenTag($tag,$attr);
}
}
}
}
function OpenTag($tag, $attr)
{
// Opening tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,true);
if($tag=='A')
$this->HREF = $attr['HREF'];
if($tag=='BR')
$this->Ln(5);
}
function CloseTag($tag)
{
// Closing tag
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,false);
if($tag=='A')
$this->HREF = '';
}
function SetStyle($tag, $enable)
{
// Modify style and select corresponding font
$this->$tag += ($enable ? 1 : -1);
$style = '';
foreach(array('B', 'I', 'U') as $s)
{
if($this->$s>0)
$style .= $s;
}
$this->SetFont('',$style);
}
function PutLink($URL, $txt)
{
// Put a hyperlink
$this->SetTextColor(0,0,255);
$this->SetStyle('U',true);
$this->Write(5,$txt,$URL);
$this->SetStyle('U',false);
$this->SetTextColor(0);
}
}
$html = 'You can now easily print text mixing different styles: <b>bold</b>, <i>italic</i>,
<u>underlined</u>, or <b><i><u>all at once</u></i></b>!<br><br>You can also insert links on
text, such as <a href="http://www.fpdf.org">www.fpdf.org</a>, or on an image: click on the logo.';
$pdf = new PDF();
// First page
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->Write(5,"To find out what's new in this tutorial, click ");
$pdf->SetFont('','U');
$link = $pdf->AddLink();
$pdf->Write(5,'here',$link);
$pdf->SetFont('');
// Second page
$pdf->AddPage();
$pdf->SetLink($link);
$pdf->Image('logo.png',10,12,30,0,'','http://www.fpdf.org');
$pdf->SetLeftMargin(45);
$pdf->SetFontSize(14);
$pdf->WriteHTML($html);
$pdf->Output();
?>

182
fpdf186/tutorial/tuto7.htm Normal file
View File

@ -0,0 +1,182 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Adding new fonts and encodings</title>
<link type="text/css" rel="stylesheet" href="../fpdf.css">
</head>
<body>
<h1>Adding new fonts and encodings</h1>
This tutorial explains how to use TrueType, OpenType and Type1 fonts so that you are not limited to the
standard fonts anymore. The other benefit is that you can choose the text encoding, which allows you to
use other languages than the Western ones (the standard fonts support only cp1252 aka windows-1252).
<br>
<br>
For OpenType, only the format based on TrueType is supported (not the one based on Type1).<br>
For Type1, you will need the corresponding AFM file (it is usually provided with the font).
<br>
<br>
Adding a new font requires two steps:
<ul>
<li>Generation of the font definition file</li>
<li>Declaration of the font in the script</li>
</ul>
<h2>Generation of the font definition file</h2>
The first step consists in generating a PHP file containing all the information needed by FPDF;
in addition, the font file is compressed. To do this, a helper script is provided in the makefont
directory of the package: makefont.php. It contains the following function:
<br>
<br>
<code>MakeFont(<b>string</b> fontfile [, <b>string</b> enc [, <b>boolean</b> embed [, <b>boolean</b> subset]]])</code>
<dl class="param" style="margin-bottom:2em">
<dt><code>fontfile</code></dt>
<dd>
<p>Path to the .ttf, .otf or .pfb file.</p>
</dd>
<dt><code>enc</code></dt>
<dd>
<p>Name of the encoding to use. Default value: <code>cp1252</code>.</p>
</dd>
<dt><code>embed</code></dt>
<dd>
<p>Whether to embed the font or not. Default value: <code>true</code>.</p>
</dd>
<dt><code>subset</code></dt>
<dd>
<p>Whether to subset the font or not. Default value: <code>true</code>.</p>
</dd>
</dl>
The first parameter is the name of the font file. The extension must be either .ttf, .otf or .pfb and
determines the font type. If your Type1 font is in ASCII format (.pfa), you can convert it to binary
(.pfb) with the help of <a href="http://www.lcdf.org/~eddietwo/type/#t1utils" target="_blank">t1utils</a>.
<br>
<br>
For Type1 fonts, the corresponding .afm file must be present in the same directory.
<br>
<br>
The encoding defines the association between a code (from 0 to 255) and a character. The first 128 are
always the same and correspond to ASCII; the following are variable. Encodings are stored in .map
files. The available ones are:
<ul>
<li>cp1250 (Central Europe)</li>
<li>cp1251 (Cyrillic)</li>
<li>cp1252 (Western Europe)</li>
<li>cp1253 (Greek)</li>
<li>cp1254 (Turkish)</li>
<li>cp1255 (Hebrew)</li>
<li>cp1257 (Baltic)</li>
<li>cp1258 (Vietnamese)</li>
<li>cp874 (Thai)</li>
<li>ISO-8859-1 (Western Europe)</li>
<li>ISO-8859-2 (Central Europe)</li>
<li>ISO-8859-4 (Baltic)</li>
<li>ISO-8859-5 (Cyrillic)</li>
<li>ISO-8859-7 (Greek)</li>
<li>ISO-8859-9 (Turkish)</li>
<li>ISO-8859-11 (Thai)</li>
<li>ISO-8859-15 (Western Europe)</li>
<li>ISO-8859-16 (Central Europe)</li>
<li>KOI8-R (Russian)</li>
<li>KOI8-U (Ukrainian)</li>
</ul>
Of course, the font must contain the characters corresponding to the selected encoding.
<br>
<br>
The third parameter indicates whether the font should be embedded in the PDF or not. When a font is
not embedded, it is searched in the system. The advantage is that the PDF file is smaller; on the
other hand, if it is not available, then a substitution font is used. So you should ensure that the
needed font is installed on the client systems. Embedding is the recommended option to guarantee a
correct rendering.
<br>
<br>
The last parameter indicates whether subsetting should be used, that is to say, whether only
the characters from the selected encoding should be kept in the embedded font. As a result,
the size of the PDF file can be greatly reduced, especially if the original font was big.
<br>
<br>
After you have called the function (create a new file for this and include makefont.php), a .php file
is created, with the same name as the font file. You may rename it if you wish. If the case of embedding,
the font file is compressed and gives a second file with .z as extension (except if the compression
function is not available, it requires Zlib). You may rename it too, but in this case you have to change
the variable <code>$file</code> in the .php file accordingly.
<br>
<br>
Example:
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'makefont/makefont.php'</span><span class="kw">);
</span>MakeFont<span class="kw">(</span><span class="str">'C:\\Windows\\Fonts\\comic.ttf'</span><span class="kw">,</span><span class="str">'cp1252'</span><span class="kw">);
</span>?&gt;</code></pre>
</div>
which gives the files comic.php and comic.z.
<br>
<br>
Then copy the generated files to the font directory. If the font file could not be compressed, copy
it directly instead of the .z version.
<br>
<br>
Another way to call MakeFont() is through the command line:
<br>
<br>
<kbd>php makefont\makefont.php C:\Windows\Fonts\comic.ttf cp1252</kbd>
<br>
<br>
Finally, for TrueType and OpenType fonts, you can also generate the files
<a href="http://www.fpdf.org/makefont/">online</a> instead of doing it manually.
<h2>Declaration of the font in the script</h2>
The second step is simple. You just need to call the <a href='../doc/addfont.htm'>AddFont()</a> method:
<div class="source">
<pre><code>$pdf<span class="kw">-&gt;</span>AddFont<span class="kw">(</span><span class="str">'Comic'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span><span class="str">'comic.php'</span><span class="kw">);
</span></code></pre>
</div>
And the font is now available (in regular and underlined styles), usable like the others. If we
had worked with Comic Sans MS Bold (comicbd.ttf), we would have written:
<div class="source">
<pre><code>$pdf<span class="kw">-&gt;</span>AddFont<span class="kw">(</span><span class="str">'Comic'</span><span class="kw">,</span><span class="str">'B'</span><span class="kw">,</span><span class="str">'comicbd.php'</span><span class="kw">);
</span></code></pre>
</div>
<h2>Example</h2>
Now let's see a complete example. We will use the <a href="https://fonts.google.com/specimen/Ceviche+One" target="_blank">Ceviche One</a> font.
The first step is the generation of the font files:
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'makefont/makefont.php'</span><span class="kw">);
</span>MakeFont<span class="kw">(</span><span class="str">'CevicheOne-Regular.ttf'</span><span class="kw">,</span><span class="str">'cp1252'</span><span class="kw">);
</span>?&gt;</code></pre>
</div>
The script produces the following output:
<br>
<br>
Font file compressed: CevicheOne-Regular.z<br>
Font definition file generated: CevicheOne-Regular.php<br>
<br>
Alternatively we could have used the command line:
<br>
<br>
<kbd>php makefont\makefont.php CevicheOne-Regular.ttf cp1252</kbd>
<br>
<br>
or used the online generator.
<br>
<br>
We can now copy the two generated files to the font directory and write the script:
<div class="source">
<pre><code>&lt;?php
<span class="kw">require(</span><span class="str">'fpdf.php'</span><span class="kw">);
</span>$pdf <span class="kw">= new </span>FPDF<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>AddFont<span class="kw">(</span><span class="str">'CevicheOne'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span><span class="str">'CevicheOne-Regular.php'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>AddPage<span class="kw">();
</span>$pdf<span class="kw">-&gt;</span>SetFont<span class="kw">(</span><span class="str">'CevicheOne'</span><span class="kw">,</span><span class="str">''</span><span class="kw">,</span>45<span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Write<span class="kw">(</span>10<span class="kw">,</span><span class="str">'Enjoy new fonts with FPDF!'</span><span class="kw">);
</span>$pdf<span class="kw">-&gt;</span>Output<span class="kw">();
</span>?&gt;</code></pre>
</div>
<p class='demo'><a href='tuto7.php' target='_blank' class='demo'>[Run]</a></p>
</body>
</html>

View File

@ -0,0 +1,10 @@
<?php
require('../fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('CevicheOne','','CevicheOne-Regular.php','.');
$pdf->AddPage();
$pdf->SetFont('CevicheOne','',45);
$pdf->Write(10,'Enjoy new fonts with FPDF!');
$pdf->Output();
?>