first commit
This commit is contained in:
@@ -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épè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.
|
||||
@@ -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!"
|
||||
@@ -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.
|
||||
@@ -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.
@@ -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
|
||||
@@ -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=ISO-8859-1">
|
||||
<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>: Esempio minimo</li>
|
||||
<li><a href="tuto2.htm">Tutorial 2</a>: Intestazione, piè di pagina, cambio pagina e immagini</li>
|
||||
<li><a href="tuto3.htm">Tutorial 3</a>: Ritorno a capo e colori</li>
|
||||
<li><a href="tuto4.htm">Tutorial 4</a>: Multi-colonne</li>
|
||||
<li><a href="tuto5.htm">Tutorial 5</a>: Tabelle</li>
|
||||
<li><a href="tuto6.htm">Tutorial 6</a>: Link e testo scorrevole</li>
|
||||
<li><a href="tuto7.htm">Tutorial 7</a>: Aggiunta di nuovi font e supporto codifica</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
// Generation of font definition file for tutorial 7
|
||||
require('../makefont/makefont.php');
|
||||
|
||||
MakeFont('calligra.ttf','cp1252');
|
||||
?>
|
||||
@@ -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=ISO-8859-1">
|
||||
<title>Esempio minimo</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Esempio minimo</h1>
|
||||
Cominciamo con un esempio classico:
|
||||
<div class="source">
|
||||
<pre><code><?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">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></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">-></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">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto1.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Dopo aver incluso la libreria, creiamo un oggetto FPDF.
|
||||
Il <a href='../doc/__construct.htm'>costruttore</a> viene usato, qui sopra, con i valori di default:
|
||||
le pagine sono formato A4, verticale, e con unità di misura in
|
||||
millimetri. Sarebbe possibile specificarli esplicitamente con:
|
||||
<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>
|
||||
E' possibile usare il formato orrizzontale (<code>L</code>), altri tipi di formati (come <code>A3</code>
|
||||
e <code>A5</code>) e unità di misura (<code>pt</code>, <code>cm</code>, <code>in</code>).
|
||||
<br>
|
||||
<br>
|
||||
Per il momento non ci sono altri formato pagina. Dobbiamo aggiungerlo con <a href='../doc/addpage.htm'>AddPage()</a>. L'origine
|
||||
è all'angolo superiore-sinistro e la posizione attuale è messa per difetto a 1 cm dai confini; i
|
||||
margini possono essere cambiati con <a href='../doc/setmargins.htm'>SetMargins()</a>.
|
||||
<br>
|
||||
<br>
|
||||
Prima che si possa stampare il testo, è obbligatorio selezionare una fonte con <a href='../doc/setfont.htm'>SetFont()</a>.
|
||||
Scegliamo Arial bold (grassetto) 16:
|
||||
<div class="source">
|
||||
<pre><code>$pdf<span class="kw">-></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>
|
||||
Avremmo potuto specificare italic (corsivo) con I, sottolineato con U o un font regolare con una stringa
|
||||
vuota (o nessuna combinazione). Notare che la grandezza dei font è data in punti, non i millimetri
|
||||
(o un'altra unità utente); è l'unica eccezione. Gli altri font standard sono Times, Courier, Symbol
|
||||
e ZapfDingbats.<br>
|
||||
<br>
|
||||
Possiamo ora stampare una cella con <a href='../doc/cell.htm'>Cell()</a>. Una cella è un'area rettangolare, possibilmente
|
||||
incorniciata che contiene del testo. L'output è alla posizione attuale. Specifichiamo le sue
|
||||
dimensioni, il suo testo (centrato o allineato), se i bordi debbano essere disegnati, e dove
|
||||
la posizione attuale si debba muovere dopo (a destra, sotto o all'inizio della prossima linea).
|
||||
Per aggiungere una cornice, si fa così:
|
||||
<div class="source">
|
||||
<pre><code>$pdf<span class="kw">-></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>
|
||||
Per aggiungere una prossima nuova cella con il testo centrato e andando a capo, dobbiamo
|
||||
fare così:
|
||||
<div class="source">
|
||||
<pre><code>$pdf<span class="kw">-></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>
|
||||
Note: L'interruzione di linea può essere fatta anche con <a href='../doc/ln.htm'>Ln()</a>. Questo metodo permette di
|
||||
specificare anche l'altezza dell'interruzione.
|
||||
<br>
|
||||
<br>
|
||||
Finalmente il documento è chiuso e spedito al browser con <a href='../doc/output.htm'>Output()</a>. Ora possiamo
|
||||
salvarlo in un file.
|
||||
<br>
|
||||
<br>
|
||||
Attenzione: quando, nel caso, il PDF viene spedito al browser, non deve essere processato
|
||||
nient'altro, ne prima ne dopo (l'ultimo spazio o ritorno a capo non conta). Se si inoltra
|
||||
qualcos'altro prima, riceveremo il messaggio di errore: "Alcuni dati sono stati già passati
|
||||
al browser, non è possibile inviare il file PDF" o qualcosa del genere.
|
||||
Se inseriamo qualcos'altro dopo, il browser potrebbe visualizzare un pagina bianca.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -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=ISO-8859-1">
|
||||
<title>Intestazione, piè di pagina, cambio pagina e immagini</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Intestazione, piè di pagina, cambio pagina e immagini</h1>
|
||||
Ecco un esempio di due pagine con intestazione, piè di pagina, e logo:
|
||||
<div class="source">
|
||||
<pre><code><?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-></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-></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-></span>Cell<span class="kw">(</span>80<span class="kw">);
|
||||
</span><span class="cmt">// Title
|
||||
</span>$<span class="kw">this-></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-></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-></span>SetY<span class="kw">(-</span>15<span class="kw">);
|
||||
</span><span class="cmt">// Arial italic 8
|
||||
</span>$<span class="kw">this-></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-></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-></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">-></span>AliasNbPages<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></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"><=</span>40<span class="kw">;</span>$i<span class="kw">++)
|
||||
</span>$pdf<span class="kw">-></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">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto2.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Questo esempio fa uso dei metodi <a href='../doc/header.htm'>Header()</a> e <a href='../doc/footer.htm'>Footer()</a> per processare le intestazioni e
|
||||
i piè di pagina. Sono richiamati automaticamente. Esistono già nella classe FPDF ma non fanno nulla,
|
||||
quindi dobbiamo estendere la classe e fare un override di questi metodi.
|
||||
<br>
|
||||
<br>
|
||||
Il logo è stampato con il metodo <a href='../doc/image.htm'>Image()</a> specificando il suo angolo in alto a sinistra e
|
||||
la sua larghezza. L'altezza è calcolata automaticamente per rispettare le proporzioni dell'immagine.
|
||||
<br>
|
||||
<br>
|
||||
Per stampare il numero della pagina, un valore null è passato alla larghezza della cella. Significa che la cella
|
||||
dovrebbe estendersi fino al margine destro della pagina; questo è comodo per centrare il testo. Il numero della pagina
|
||||
corrente è ritornato dal metodo <a href='../doc/pageno.htm'>PageNo()</a>; ed il numero totale delle pagine è ottenibile
|
||||
attraverso il codice speciale <code>{nb}</code> che è sostituito nel testo quando il documento è concluso
|
||||
(a condizione di chiamare prima <a href='../doc/aliasnbpages.htm'>AliasNbPages()</a>).
|
||||
<br>
|
||||
Nota che l'uso del metodo <a href='../doc/sety.htm'>SetY()</a> che permette di posizionarsi ad una posizione assoluta nella
|
||||
pagina, parte dall'inizio o dal fondo della pagina.
|
||||
<br>
|
||||
<br>
|
||||
Qui si utilizza un'altra caratteristica interessante: l'interruzione di pagina automatica. Non appena la cella sorpassa
|
||||
un limite nella pagina (di predefinito sono 2 centimetri dal fondo), si lancia l'interruzione
|
||||
e il font è ripristinato. Sebbene l'intestazione ed il piè di pagina abbiano il loro font (Arial), il corpo
|
||||
continua con Times. Questo meccanismo di ripristino automatico si applica anche ai colori e alla larghezza della
|
||||
linea. Il limite a cui si evoca l'interruzione di pagina può essere impostato con <a href='../doc/setautopagebreak.htm'>SetAutoPageBreak()</a>.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -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=ISO-8859-1">
|
||||
<title>Ritorno a capo e colori</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ritorno a capo e colori</h1>
|
||||
Continuiamo con un esempio in cui si stampano paragrafi giustificati. Si illustra anche l'uso
|
||||
dei colori.
|
||||
<div class="source">
|
||||
<pre><code><?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-></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-></span>GetStringWidth<span class="kw">(</span>$title<span class="kw">)+</span>6<span class="kw">;
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></span>SetLineWidth<span class="kw">(</span>1<span class="kw">);
|
||||
</span><span class="cmt">// Title
|
||||
</span>$<span class="kw">this-></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-></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-></span>SetY<span class="kw">(-</span>15<span class="kw">);
|
||||
</span><span class="cmt">// Arial italic 8
|
||||
</span>$<span class="kw">this-></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-></span>SetTextColor<span class="kw">(</span>128<span class="kw">);
|
||||
</span><span class="cmt">// Page number
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></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-></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-></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-></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-></span>Ln<span class="kw">();
|
||||
</span><span class="cmt">// Mention in italics
|
||||
</span>$<span class="kw">this-></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-></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-></span>AddPage<span class="kw">();
|
||||
</span>$<span class="kw">this-></span>ChapterTitle<span class="kw">(</span>$num<span class="kw">,</span>$title<span class="kw">);
|
||||
</span>$<span class="kw">this-></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">-></span>SetTitle<span class="kw">(</span>$title<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>SetAuthor<span class="kw">(</span><span class="str">'Jules Verne'</span><span class="kw">);
|
||||
</span>$pdf<span class="kw">-></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">-></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">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto3.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Il metodo <a href='../doc/getstringwidth.htm'>GetStringWidth()</a> permette di determinare la lunghezza di una stringa nel font corrente,
|
||||
è qui utilizzata per calcolare la posizione e la larghezza della cornice che circonda il titolo.
|
||||
Quando i colori sono impostati (attraverso <a href='../doc/setdrawcolor.htm'>SetDrawColor()</a>, <a href='../doc/setfillcolor.htm'>SetFillColor()</a> e <a href='../doc/settextcolor.htm'>SetTextColor()</a>) e lo
|
||||
spessore della linea è impostata ad 1 mm (invece che 0.2 di predefinito) con <a href='../doc/setlinewidth.htm'>SetLineWidth()</a>. Alla fine
|
||||
si mostra la cella (l'ultimo parametro a <code>true</code> indica che lo sfondo deve essere riempito).
|
||||
<br>
|
||||
<br>
|
||||
Il metodo utilizzato per stampare i paragrafi è <a href='../doc/multicell.htm'>MultiCell()</a>. Ogni volta che una riga raggiunge
|
||||
l'estremità destra della cella, o se si raggiunge un ritorno a capo, si lancia un'interruzione di riga
|
||||
e si crea automaticamente una nuova cella creata sotto quella precedente. Il testo è giustificato in maniera
|
||||
predefinita.
|
||||
<br>
|
||||
<br>
|
||||
Si definiscono due proprietà del documento: il titolo (<a href='../doc/settitle.htm'>SetTitle()</a>) e l'autore (<a href='../doc/setauthor.htm'>SetAuthor()</a>).
|
||||
Ci sono molti modi per mostrarli in un riproduttore di PDF. Il primo modo è aprire direttamente il PDF
|
||||
con il lettore PDF e visualizzare le proprietà del documento, spesso attraverso il menù File. A volte si può anche
|
||||
fare click con il tasto destro e selezionare Proprietà del documento (o qualcosa del genere). Un altro modo è di premere
|
||||
la combinazione Ctrl+D.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -0,0 +1,131 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Multi-colonne</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Multi-colonne</h1>
|
||||
Questo esempio è una variante del precedente e mostra come sia possibile distribuire il testo su più
|
||||
colonne.
|
||||
<div class="source">
|
||||
<pre><code><?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-></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-></span>GetStringWidth<span class="kw">(</span>$title<span class="kw">)+</span>6<span class="kw">;
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></span>SetLineWidth<span class="kw">(</span>1<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></span>Ln<span class="kw">(</span>10<span class="kw">);
|
||||
</span><span class="cmt">// Save ordinate
|
||||
</span>$<span class="kw">this-></span>y0 <span class="kw">= </span>$<span class="kw">this-></span>GetY<span class="kw">();
|
||||
}
|
||||
|
||||
function </span>Footer<span class="kw">()
|
||||
{
|
||||
</span><span class="cmt">// Page footer
|
||||
</span>$<span class="kw">this-></span>SetY<span class="kw">(-</span>15<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></span>SetTextColor<span class="kw">(</span>128<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></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-></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-></span>SetLeftMargin<span class="kw">(</span>$x<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></span>col<span class="kw"><</span>2<span class="kw">)
|
||||
{
|
||||
</span><span class="cmt">// Go to next column
|
||||
</span>$<span class="kw">this-></span>SetCol<span class="kw">(</span>$<span class="kw">this-></span>col<span class="kw">+</span>1<span class="kw">);
|
||||
</span><span class="cmt">// Set ordinate to top
|
||||
</span>$<span class="kw">this-></span>SetY<span class="kw">(</span>$<span class="kw">this-></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-></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-></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-></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-></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-></span>Ln<span class="kw">(</span>4<span class="kw">);
|
||||
</span><span class="cmt">// Save ordinate
|
||||
</span>$<span class="kw">this-></span>y0 <span class="kw">= </span>$<span class="kw">this-></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-></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-></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-></span>Ln<span class="kw">();
|
||||
</span><span class="cmt">// Mention
|
||||
</span>$<span class="kw">this-></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-></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-></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-></span>AddPage<span class="kw">();
|
||||
</span>$<span class="kw">this-></span>ChapterTitle<span class="kw">(</span>$num<span class="kw">,</span>$title<span class="kw">);
|
||||
</span>$<span class="kw">this-></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">-></span>SetTitle<span class="kw">(</span>$title<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>SetAuthor<span class="kw">(</span><span class="str">'Jules Verne'</span><span class="kw">);
|
||||
</span>$pdf<span class="kw">-></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">-></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">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto4.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Il metodo principale utilizzato è <a href='../doc/acceptpagebreak.htm'>AcceptPageBreak()</a>. Permette di accettare o no un'interruzione automatica di
|
||||
pagina. Rifiutandolo e alterando il margine alla posizione corrrente, si raggiunge il layout desiderato.
|
||||
<br>
|
||||
Per il resto non ci sono molti cambiamenti; due proprietà sono state aggiunte alla classe per salvare
|
||||
il numero della colonna e la posizione quando inizia la colonna, e la chiamata a <a href='../doc/multicell.htm'>MultiCell()</a> specifica
|
||||
una larghezza di 6 centimetri.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -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=ISO-8859-1">
|
||||
<title>Tabelle</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Tabelle</h1>
|
||||
Questo tutorial mostra modalità differenti per creare tabelle.
|
||||
<div class="source">
|
||||
<pre><code><?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-></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-></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-></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-></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"><</span>count<span class="kw">(</span>$header<span class="kw">);</span>$i<span class="kw">++)
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></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-></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-></span>Ln<span class="kw">();
|
||||
}
|
||||
</span><span class="cmt">// Closing line
|
||||
</span>$<span class="kw">this-></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-></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-></span>SetTextColor<span class="kw">(</span>255<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></span>SetLineWidth<span class="kw">(</span>.3<span class="kw">);
|
||||
</span>$<span class="kw">this-></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"><</span>count<span class="kw">(</span>$header<span class="kw">);</span>$i<span class="kw">++)
|
||||
</span>$<span class="kw">this-></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-></span>Ln<span class="kw">();
|
||||
</span><span class="cmt">// Color and font restoration
|
||||
</span>$<span class="kw">this-></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-></span>SetTextColor<span class="kw">(</span>0<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></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-></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-></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">-></span>LoadData<span class="kw">(</span><span class="str">'countries.txt'</span><span class="kw">);
|
||||
</span>$pdf<span class="kw">-></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">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></span>BasicTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></span>ImprovedTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></span>FancyTable<span class="kw">(</span>$header<span class="kw">,</span>$data<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto5.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Dato che una tabella è solo un'insieme di celle, è naturale costruirne una da esse. Il primo
|
||||
esempio è praticato con l'approccio più basilare possibile: semplici celle con bordi, tutte alla stessa dimensione
|
||||
e allineate a sinistra. Il risultato è rudimentale ma veloce da ottenere.
|
||||
<br>
|
||||
<br>
|
||||
La seconda tabella porta alcune migliorie: ogni colonna ha una sua larghezza, intestazione e sono centrate,
|
||||
numerate e allineate a destra. In più, sono state rimosse le righe orizzontali. Questo si fa attraverso
|
||||
il parametro <code>border</code> del metodo <a href='../doc/cell.htm'>Cell()</a> che specifica quali lati della cella debbano essere
|
||||
disegnati. Qui vogliamo il lato sinistro (<code>L</code>) e destro (<code>R</code>). Rimane il
|
||||
problema della linea orizzontale per finire la tabella. Ci sono due possibilità: sia
|
||||
controllare quando si arriva all'ultima riga del ciclo, in questo caso utilizzare <code>LRB</code> per il parametro <code>border</code>
|
||||
or, come è stato fatto qui, aggiungere la riga quando finisce il ciclo.
|
||||
<br>
|
||||
<br>
|
||||
La terza tabella è simile alla seconda ma usa i colori. I colori di riempimento, del testo, e della linea
|
||||
sono semplicemente specificati. L'alternaggio della colorazione delle righe è ottenuto alternando trasparenza
|
||||
e colorazione delle celle.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -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=ISO-8859-1">
|
||||
<title>Link e testo scorrevole</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Link e testo scorrevole</h1>
|
||||
Questo tutorial spiega come inserire link (interni ed esterni) e mostrare una nuova modalità di
|
||||
scrittura. Contiene anche un parser HTML minimale.
|
||||
<div class="source">
|
||||
<pre><code><?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">'/<(.*)>/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">=></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-></span>HREF<span class="kw">)
|
||||
</span>$<span class="kw">this-></span>PutLink<span class="kw">(</span>$<span class="kw">this-></span>HREF<span class="kw">,</span>$e<span class="kw">);
|
||||
else
|
||||
</span>$<span class="kw">this-></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-></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-></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-></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-></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-></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-></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-></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-></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-></span>$s<span class="kw">></span>0<span class="kw">)
|
||||
</span>$style <span class="kw">.= </span>$s<span class="kw">;
|
||||
}
|
||||
</span>$<span class="kw">this-></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-></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-></span>SetStyle<span class="kw">(</span><span class="str">'U'</span><span class="kw">,</span>true<span class="kw">);
|
||||
</span>$<span class="kw">this-></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-></span>SetStyle<span class="kw">(</span><span class="str">'U'</span><span class="kw">,</span>false<span class="kw">);
|
||||
</span>$<span class="kw">this-></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: <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.'</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">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></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">-></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">-></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">-></span>AddLink<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></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">-></span>SetFont<span class="kw">(</span><span class="str">''</span><span class="kw">);
|
||||
</span><span class="cmt">// Second page
|
||||
</span>$pdf<span class="kw">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></span>SetLink<span class="kw">(</span>$link<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></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">-></span>SetLeftMargin<span class="kw">(</span>45<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>SetFontSize<span class="kw">(</span>14<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>WriteHTML<span class="kw">(</span>$html<span class="kw">);
|
||||
</span>$pdf<span class="kw">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto6.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
Il nuovo metodo per mostrare il testo è <a href='../doc/write.htm'>Write()</a>. È molto simile a <a href='../doc/multicell.htm'>MultiCell()</a>; le differenze sono:
|
||||
<ul>
|
||||
<li>La fine della linea è al margine destro ed il testo inizia al margine a sinistra</li>
|
||||
<li>The current position moves at the end of the text</li>
|
||||
</ul>
|
||||
Quindi per permettere di scrivere del testo, alterare lo stile del carattere, quindi continuare dal punto esatto
|
||||
dove eravamo rimasti. Purtroppo però non si può giustificare il testo.
|
||||
<br>
|
||||
<br>
|
||||
Il metodo è utilizzato sulla prima pagina per inserire un link che punti alla seconda pagina. L'inizio
|
||||
della frase è scritto in testo normale, quindi si cambia in sottolineato e si conclude. Il link
|
||||
è creato con <a href='../doc/addlink.htm'>AddLink()</a>, che ritorna un identificatore per il link. L'identificatore è
|
||||
passato come terzo parametro di Write(). Una volta che la seconda pagina è creata, usiamo <a href='../doc/setlink.htm'>SetLink()</a> per
|
||||
creare un link che punti all'inizio della pagina corrente.
|
||||
<br>
|
||||
<br>
|
||||
Quindi inseriamo un'immagine con un link esterno su di essa. Un link esterno è semplicemente un URL. È passato come
|
||||
ultimo parametro di <a href='../doc/image.htm'>Image()</a>.
|
||||
<br>
|
||||
<br>
|
||||
Concludendo, il margine sinistro si sposta dopo l'immagine con <a href='../doc/setleftmargin.htm'>SetLeftMargin()</a> e del testo è mostrato in
|
||||
formato HTML. È utilizzato un parser HTML molto semplice per questo scopo, basato su espressioni regolari.
|
||||
I tag riconosciuti sono <b>, <i>, <u>, <a> e <br>; gli altri sono
|
||||
ignorati. Il parser fa anche uso del metodo Write(). Un link esterno è inserito allo stesso modo di
|
||||
uno interno (terzo parametro di Write()). Notare che anche <a href='../doc/cell.htm'>Cell()</a> permette di inserire link.
|
||||
</body>
|
||||
</html>
|
||||
@@ -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();
|
||||
?>
|
||||
@@ -0,0 +1,192 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Aggiunta di nuovi font e supporto codifica</title>
|
||||
<link type="text/css" rel="stylesheet" href="../fpdf.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Aggiunta di nuovi font e supporto codifica</h1>
|
||||
Questo tutorial spiega come usare i font TrueType, OpenType e Type1 in modo da non essere più limitati ai
|
||||
font standard predefiniti. L'altro beneficio è che si può scegliere una codifica del testo, permettendo
|
||||
di utilizzare altre lingue oltre a quelle occidentali (i font standard supportano solo cp1252, anche noto come windows-1252).
|
||||
<br>
|
||||
<br>
|
||||
Per OpenType, è supportato solo il formato basato su TrueType (non quello basato su Type1).<br>
|
||||
Per Type1, c'è bisogno del corrispondente file AFM (di solito è fornito insieme al font).
|
||||
<br>
|
||||
<br>
|
||||
Aggiungere un nuovo font richiede due passi:
|
||||
<ul>
|
||||
<li>Generazione di un file di definizione</li>
|
||||
<li>Dichiarazione di un font nello script</li>
|
||||
</ul>
|
||||
|
||||
<h2>Generatore di un file di definizione</h2>
|
||||
Il primo passo consiste nel generare un file PHP contenente tutte le informazioni che necessita FPDF;
|
||||
in aggiunta, il file del font è compresso. Per farlo, uno script di aiuto è fornito nella cartella makefont
|
||||
del pacchetto: makefont.php. Contiene le seguenti funzioni:
|
||||
<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>Percorso del file .ttf, .otf or .pfb.</p>
|
||||
</dd>
|
||||
<dt><code>enc</code></dt>
|
||||
<dd>
|
||||
<p>Nome della codifica in uso. Predefinito: <code>cp1252</code>.</p>
|
||||
</dd>
|
||||
<dt><code>embed</code></dt>
|
||||
<dd>
|
||||
<p>Se incorporare il font o meno. Predefinito: <code>true</code>.</p>
|
||||
</dd>
|
||||
<dt><code>subset</code></dt>
|
||||
<dd>
|
||||
<p>Se inserire il sottoinsieme del font o meno. Predefinito: <code>true</code>.</p>
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
Il primo parametro è il nome del file del font. L'estensione può essere sia .ttf, .otf o .pfb e
|
||||
determina il tipo di font. Se si utilizza il font Type1 con il formato è ASCII (.pfa), puoi convertirlo in binario
|
||||
(.pfb) con l'aiuto di <a href="http://www.lcdf.org/~eddietwo/type/#t1utils" target="_blank">t1utils</a>.
|
||||
<br>
|
||||
<br>
|
||||
Per i font Type1, il file .afm corrispondente deve essere presente nella stessa cartella.
|
||||
<br>
|
||||
<br>
|
||||
La codifica definisce l'associazione fra un codice (da 0 a 255) ed il carattere. I primi 128 sono
|
||||
sempre gli stessi corrispondenti all'ASCII; i successivi sono disponibili. Le codifiche sono salvate in file .map.
|
||||
Quelle disponibili sono:
|
||||
<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>
|
||||
Ovviamente il font deve contenere i caratteri corrispondenti alla codifica selezionata.
|
||||
<br>
|
||||
|
||||
<br>
|
||||
Il terzo parametro indica se il font debba essere incorporato nel PDF o meno. Quando un font non è
|
||||
incorporato, sarà cercato nel sistema. Il vantaggio è che il file PDF è più leggero; se però
|
||||
il font non fosse disponibile, sarà utilizzato un font sostitutivo. Occorre verificare che
|
||||
il font richiesto sia installato sui sistemi dei destinatari. L'incorporazione è l'opzione raccomandata per garantire
|
||||
la portabilità.
|
||||
<br>
|
||||
<br>
|
||||
|
||||
L'ultimo parametro indica se utilizzare un sottoinsieme o meno, il chè significa che solo
|
||||
i caratteri della codifica seelezionata saranno mantenuti nel font incorporato. Come risultato,
|
||||
la dimensione del PDF può essere ridotta di molto, specialmente se il font originale era pesante.
|
||||
<br>
|
||||
<br>
|
||||
Dopo aver chiamato la funzione (per fare questo crea un nuovo file e includi makefont.php), sarà creato un file .php,
|
||||
con lo stesso nome del file del font. Puoi rinominarlo se lo desideri. Per incorporarlo,
|
||||
il file del font è compresso e si ottiene un secondo file con estensione .z (tranne se la funzione per la compressione
|
||||
non sia disponibile, dato che richiede Zlib). Puoi rinominare anche quest'ultimo, ma in questo caso occorre cambiare
|
||||
la variabile <code>$file</code> del file .php di conseguenza.
|
||||
<br>
|
||||
<br>
|
||||
Esempio:
|
||||
<div class="source">
|
||||
<pre><code><?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>?></code></pre>
|
||||
</div>
|
||||
|
||||
che genera i file comic.php e comic.z.
|
||||
<br>
|
||||
<br>
|
||||
Copiare i file generati nella cartella font. Se il font non può essere compresso, copialo
|
||||
direttamente al posto della versione .z.
|
||||
<br>
|
||||
<br>
|
||||
In altro modo è utilizzare MakeFont() da linea di comando:
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<kbd>php makefont\makefont.php C:\Windows\Fonts\comic.ttf cp1252</kbd>
|
||||
<br>
|
||||
|
||||
<br>
|
||||
Concludendo, per i font TrueType e OpenType fonts, puoi anche generare i file
|
||||
<a href="http://www.fpdf.org/makefont/">online</a> invece che farlo manualmente.
|
||||
|
||||
|
||||
<h2>Dichiarazione dei font nello script</h2>
|
||||
Il secondo file è semplice. C'è solo bisogno di chiamare il metodo <a href='../doc/addfont.htm'>AddFont()</a>:
|
||||
<div class="source">
|
||||
<pre><code>$pdf<span class="kw">-></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>
|
||||
Il font sarà ora disponibile (in forma di stili regolare e sottolineato), utilizzabile come gli altri. Se abbiamo
|
||||
lavorato con Comic Sans MS Bold (comicbd.ttf), dovremmo avere scritto:
|
||||
<div class="source">
|
||||
<pre><code>$pdf<span class="kw">-></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>Esempio</h2>
|
||||
Ora proviamo un esempio completo. Sarà usato il font <a href="https://fonts.google.com/specimen/Ceviche+One" target="_blank">Ceviche One</a>.
|
||||
Il primo passo è la generazione dei file del font:
|
||||
<div class="source">
|
||||
<pre><code><?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>?></code></pre>
|
||||
</div>
|
||||
Lo script scaturirà alcuni avvisi:
|
||||
<br>
|
||||
<br>
|
||||
Font file compressed: CevicheOne-Regular.z<br>
|
||||
Font definition file generated: CevicheOne-Regular.php<br>
|
||||
<br>
|
||||
Alternativamente possiamo usare la linea di comando:
|
||||
<br>
|
||||
<br>
|
||||
<kbd>php makefont\makefont.php CevicheOne-Regular.ttf cp1252</kbd>
|
||||
<br>
|
||||
<br>
|
||||
o utilizzando il generatore online.
|
||||
<br>
|
||||
<br>
|
||||
Ora è possibile copiare i due file generati nella cartella font e scrivere lo script:
|
||||
<div class="source">
|
||||
<pre><code><?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">-></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">-></span>AddPage<span class="kw">();
|
||||
</span>$pdf<span class="kw">-></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">-></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">-></span>Output<span class="kw">();
|
||||
</span>?></code></pre>
|
||||
</div>
|
||||
<p class='demo'><a href='tuto7.php' target='_blank' class='demo'>[Demo]</a></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
define('FPDF_FONTPATH','.');
|
||||
require('../fpdf.php');
|
||||
|
||||
$pdf = new FPDF();
|
||||
$pdf->AddFont('CevicheOne','','CevicheOne-Regular.php');
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('CevicheOne','',45);
|
||||
$pdf->Cell(0,10,'Enjoy new fonts with FPDF!');
|
||||
$pdf->Output();
|
||||
?>
|
||||
Reference in New Issue
Block a user