Erster Commit: nativer Linux-Port aus macOS-Bytecode

Läuft die Voice Acoustic VA-Remotecontrol (AllDSP AllControl) nativ unter Linux
auf echtem wxGTK 3.0 — ohne Wine und ohne dekompilierten App-Code. Ausgeführt wird
das unveränderte Python-2.7-Bytecode aus dem macOS-.app; C-Extensions (wxGTK/numpy/
scipy/PortAudio) kommen nativ aus Debian stretch.

Enthält: va/ (Original-.pyc + pure-Python-Libs + Assets + launch.py mit den drei
Linux-Fixes), Dockerfile/run.sh/entrypoint.sh, reference/ (dekompilierter Quellcode
zum Debuggen) und README/STATUS. img.cache (378 MB, regenerierbar) ist per
.gitignore ausgeschlossen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
maik
2026-08-20 19:57:01 +02:00
co-authored by Claude Opus 4.8
commit a7c93fa266
654 changed files with 478133 additions and 0 deletions
@@ -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,19 @@
from FPDF.Bookmark import *
pdf=Bookmark()
pdf.Open()
pdf.SetFont('Arial','',15)
#Page 1
pdf.AddPage()
pdf.Bookmark('Page 1')
pdf.Bookmark('Paragraph 1',1,-1)
pdf.Cell(0,6,'Paragraph 1')
pdf.Ln(50)
pdf.Bookmark('Paragraph 2',1,-1)
pdf.Cell(0,6,'Paragraph 2')
#Page 2
pdf.AddPage()
pdf.Bookmark('Page 2')
pdf.Bookmark('Paragraph 3',1,-1)
pdf.Cell(0,6,'Paragraph 3')
pdf.Output('bookmark.pdf','F')
@@ -0,0 +1,100 @@
from FPDF.Gradients import *
pdf=Gradients()
#first page
pdf.AddPage()
pdf.SetFont('Arial','',14)
pdf.Cell(0,5,'Page 1',0,1,'C')
pdf.Ln()
#set colors for gradients (r,g,b) or (grey 0-255)
red=[255,0,0]
blue=[0,0,200]
yellow=[255,255,0]
green=[0,255,0]
white=[255]
black=[0]
#set the coordinates x1,y1,x2,y2 of the gradient (see linear_gradient_coords.jpg)
coords=[0.0,0.0,1.0,0.0]
#paint a linear gradient
pdf.LinearGradient(20,25,80,80,red,blue,coords)
#set the coordinates fx,fy,cx,cy,r of the gradient (see radial_gradient_coords.jpg)
coords=[0.5,0.5,1.0,1.0,1.2]
#paint a radial gradient
pdf.RadialGradient(110,25,80,80,white,black,coords)
#paint a coons patch mesh with default coordinates
pdf.CoonsPatchMesh(20,115,80,80,yellow, blue, green, red)
#set the coordinates for the cubic Bézier points x1,y1 ... x12, y12 of the patch (see coons_patch_mesh_coords.jpg)
coords=[0.00,0.00, 0.33,0.20, #lower left
0.67,0.00, 1.00,0.00, 0.80,0.33, #lower right
0.80,0.67, 1.00,1.00, 0.67,0.80, #upper right
0.33,1.00, 0.00,1.00, 0.20,0.67, #upper left
0.00,0.33] #lower left
coords_min=0.0 #minimum value of the coordinates
coords_max=1.0 #maximum value of the coordinates
#paint a coons patch gradient with the above coordinates
pdf.CoonsPatchMesh(110,115,80,80,yellow,blue,green,red,coords,coords_min,coords_max)
#second page
pdf.AddPage()
pdf.Cell(0,5,'Page 2',0,1,'C')
pdf.Ln()
#first patch: f = 0
patch_array={0:{},1:{},2:{},3:{}}
patch_array[0]['f']=0
patch_array[0]['points']=[0.00,0.00, 0.33,0.00,
0.67,0.00, 1.00,0.00, 1.00,0.33,
0.8,0.67, 1.00,1.00, 0.67,0.8,
0.33,1.80, 0.00,1.00, 0.00,0.67,
0.00,0.33]
patch_array[0]['colors']={}
patch_array[0]['colors'][0]={'r':255.0,'g':255.0,'b':0.0}
patch_array[0]['colors'][1]={'r':0.0,'g':0.0,'b':255.0}
patch_array[0]['colors'][2]={'r':0.0,'g':255.0,'b':0.0}
patch_array[0]['colors'][3]={'r':255.0,'g':0.0,'b':0.0}
#second patch - above the other: f = 2
patch_array[1]['f']=2
patch_array[1]['points']=[0.00,1.33,
0.00,1.67, 0.00,2.00, 0.33,2.00,
0.67,2.00, 1.00,2.00, 1.00,1.67,
1.5,1.33]
patch_array[1]['colors']={}
patch_array[1]['colors'][0]={'r':0.0,'g':0.0,'b':0.0}
patch_array[1]['colors'][1]={'r':255.0,'g':0.0,'b':255.0}
#third patch - right of the above: f = 3
patch_array[2]['f']=3
patch_array[2]['points']=[1.33,0.80,
1.67,1.50, 2.00,1.00, 2.00,1.33,
2.00,1.67, 2.00,2.00, 1.67,2.00,
1.33,2.00]
patch_array[2]['colors']={}
patch_array[2]['colors'][0]={'r':0.0,'g':255.0,'b':255.0}
patch_array[2]['colors'][1]={'r':0.0,'g':0.0,'b':0.0}
#fourth patch - below the above, which means left(?) of the above: f = 1
patch_array[3]['f']=1
patch_array[3]['points']=[2.00,0.67,
2.00,0.33, 2.00,0.00, 1.67,0.00,
1.33,0.00, 1.00,0.00, 1.00,0.33,
0.8,0.67]
patch_array[3]['colors']={}
patch_array[3]['colors'][0]={'r':0.0,'g':0.0,'b':0.0}
patch_array[3]['colors'][1]={'r':0.0,'g':0.0,'b':255.0}
coords_min=0
coords_max=2
pdf.CoonsPatchMesh(10,25,190,200,'','','','',patch_array,coords_min,coords_max)
pdf.Output('gradients.pdf','F')
@@ -0,0 +1,18 @@
<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>
<H2>Tutorials</H2>
I diversi esempi mostrano rapidamente come usare FPDF. Troverai spiegate tutte le caratteristiche principali.<BR><BR>
<A HREF="tuto1.htm">Tutorial 1</A>: Esempio minimo<BR>
<A HREF="tuto2.htm">Tutorial 2</A>: Intestazione, piè di pagina, cambio pagina e immagini<BR>
<A HREF="tuto3.htm">Tutorial 3</A>: Ritorno a capo e colori<BR>
<A HREF="tuto4.htm">Tutorial 4</A>: Multi-colunne<BR>
<A HREF="tuto5.htm">Tutorial 5</A>: Tabelle<BR>
<A HREF="tuto6.htm">Tutorial 6</A>: Links e testo scorrevole<BR>
<A HREF="tuto7.htm">Tutorial 7</A>: Aggiunta di nuovi fonts e supporto codifica<BR>
</BODY>
</HTML>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@@ -0,0 +1,91 @@
<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>
<H2>Esempio minimo</H2>
Let's start with the classic example:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
&lt;?php<br><font class="kw">require(</font><font class="str">'fpdf.php'</font><font class="kw">);<br><br></font>$pdf<font class="kw">=new </font>FPDF<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>AddPage<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>16<font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>Cell<font class="kw">(</font>40<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Hello World!'</font><font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>Output<font class="kw">();<br></font>?&gt;
</font>
</code></NOBR></TD></TR></TABLE><P></P>
<SCRIPT>
<!--
if(document.location.href.indexOf('http:')==0)
{
document.write("<P CLASS='demo'><A HREF='tuto1.php' TARGET='_blank' CLASS='demo'>[Demo]</A></P>");
}
//-->
</SCRIPT>
After including the library file, we create an FPDF object.
The <A HREF='../doc/fpdf.htm'>FPDF()</A> constructor is used here with the default values: pages are in A4 portrait and
the measure unit is millimeter. It could have been specified explicitly with:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">=new </font>FPDF<font class="kw">(</font><font class="str">'P'</font><font class="kw">,</font><font class="str">'mm'</font><font class="kw">,</font><font class="str">'A4'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
It is possible to use landscape (<TT>L</TT>), other page formats (such as <TT>Letter</TT> and
<TT>Legal</TT>) and measure units (<TT>pt</TT>, <TT>cm</TT>, <TT>in</TT>).
<BR>
<BR>
There is no page for the moment, so we have to add one with <A HREF='../doc/addpage.htm'>AddPage()</A>. The origin
is at the upper-left corner and the current position is by default placed at 1 cm from the
borders; the margins can be changed with <A HREF='../doc/setmargins.htm'>SetMargins()</A>.
<BR>
<BR>
Before we can print text, it is mandatory to select a font with <A HREF='../doc/setfont.htm'>SetFont()</A>, otherwise the
document would be invalid. We choose Arial bold 16:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>16<font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
We could have specified italics with I, underlined with U or a regular font with an empty string
(or any combination). Note that the font size is given in points, not millimeters (or another
user unit); it is the only exception. The other standard fonts are Times, Courier, Symbol and
ZapfDingbats.
<BR>
<BR>
We can now print a cell with <A HREF='../doc/cell.htm'>Cell()</A>. A cell is a rectangular area, possibly framed,
which contains some text. It is output at the current position. We specify its dimensions,
its text (centered or aligned), if borders should be drawn, and where the current position
moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>Cell<font class="kw">(</font>40<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Hello World !'</font><font class="kw">,</font>1<font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
To add a new cell next to it with centered text and go to the next line, we would do:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>Cell<font class="kw">(</font>60<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Powered by FPDF.'</font><font class="kw">,</font>0<font class="kw">,</font>1<font class="kw">,</font><font class="str">'C'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
Remark : the line break can also be done with <A HREF='../doc/ln.htm'>Ln()</A>. This method allows to specify
in addition the height of the break.
<BR>
<BR>
Finally, the document is closed and sent to the browser with <A HREF='../doc/output.htm'>Output()</A>. We could have saved
it in a file by passing the desired file name.
<BR>
<BR>
Caution: in case when the PDF is sent to the browser, nothing else must be output, not before
nor after (the least space or carriage return matters). If you send some data before, you will
get the error message: "Some data has already been output to browser, can't send PDF file". If
you send after, your browser may display a blank page.
</BODY>
</HTML>
Binary file not shown.
@@ -0,0 +1,7 @@
from fpdf import FPDF
pdf=FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)
pdf.cell(40,10,'Hello World!')
pdf.output('tuto1.pdf','F')
@@ -0,0 +1,50 @@
<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>
<H2>Intestazione, piè di pagina, cambio pagina e immagini</H2>
Here is a two page example with header, footer and logo:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
&lt;?php<br><font class="kw">require(</font><font class="str">'fpdf.php'</font><font class="kw">);<br><br>class </font>PDF <font class="kw">extends </font>FPDF<br><font class="kw">{<br></font><font class="cmt">//Page header<br></font><font class="kw">function </font>Header<font class="kw">()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Logo<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>Image<font class="kw">(</font><font class="str">'logo_pb.png'</font><font class="kw">,</font>10<font class="kw">,</font>8<font class="kw">,</font>33<font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Arial bold 15<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font>15<font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Move to the right<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>Cell<font class="kw">(</font>80<font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Title<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>Cell<font class="kw">(</font>30<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Title'</font><font class="kw">,</font>1<font class="kw">,</font>0<font class="kw">,</font><font class="str">'C'</font><font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Line break<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>Ln<font class="kw">(</font>20<font class="kw">);<br>}<br><br></font><font class="cmt">//Page footer<br></font><font class="kw">function </font>Footer<font class="kw">()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Position at 1.5 cm from bottom<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>SetY<font class="kw">(-</font>15<font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Arial italic 8<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Arial'</font><font class="kw">,</font><font class="str">'I'</font><font class="kw">,</font>8<font class="kw">);<br>&nbsp;&nbsp;&nbsp;&nbsp;</font><font class="cmt">//Page number<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$<font class="kw">this-&gt;</font>Cell<font class="kw">(</font>0<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Page '</font><font class="kw">.</font>$<font class="kw">this-&gt;</font>PageNo<font class="kw">().</font><font class="str">'/{nb}'</font><font class="kw">,</font>0<font class="kw">,</font>0<font class="kw">,</font><font class="str">'C'</font><font class="kw">);<br>}<br>}<br><br></font><font class="cmt">//Instanciation of inherited class<br></font>$pdf<font class="kw">=new </font>PDF<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>AliasNbPages<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>AddPage<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Times'</font><font class="kw">,</font><font class="str">''</font><font class="kw">,</font>12<font class="kw">);<br>for(</font>$i<font class="kw">=</font>1<font class="kw">;</font>$i<font class="kw">&lt;=</font>40<font class="kw">;</font>$i<font class="kw">++)<br>&nbsp;&nbsp;&nbsp;&nbsp;</font>$pdf<font class="kw">-&gt;</font>Cell<font class="kw">(</font>0<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Printing line number '</font><font class="kw">.</font>$i<font class="kw">,</font>0<font class="kw">,</font>1<font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>Output<font class="kw">();<br></font>?&gt;
</font>
</code></NOBR></TD></TR></TABLE><P></P>
<SCRIPT>
<!--
if(document.location.href.indexOf('http:')==0)
{
document.write("<P CLASS='demo'><A HREF='tuto2.php' TARGET='_blank' CLASS='demo'>[Demo]</A></P>");
}
//-->
</SCRIPT>
This example makes use of the <A HREF='../doc/header.htm'>Header()</A> and <A HREF='../doc/footer.htm'>Footer()</A> methods to process page headers and
footers. They are called automatically. They already exist in the FPDF class but do nothing,
therefore we have to extend the class and override them.
<BR>
<BR>
The logo is printed with the <A HREF='../doc/image.htm'>Image()</A> method by specifying its upper-left corner and
its width. The height is calculated automatically to respect the image proportions.
<BR>
<BR>
To print the page number, a null value is passed as the cell width. It means that the cell
should extend up to the right margin of the page; it is handy to center text. The current page
number is returned by the <A HREF='../doc/pageno.htm'>PageNo()</A> method; as for the total number of pages, it is obtained
by means of the special value <TT>{nb}</TT> which will be substituted on document closure
(provided you first called <A HREF='../doc/aliasnbpages.htm'>AliasNbPages()</A>).
<BR>
Note the use of the <A HREF='../doc/sety.htm'>SetY()</A> method which allows to set position at an absolute location in
the page, starting from the top or the bottom.
<BR>
<BR>
Another interesting feature is used here: the automatic page breaking. As soon as a cell would
cross a limit in the page (at 2 centimeters from the bottom by default), a break is performed
and the font restored. Although the header and footer select their own font (Arial), the body
continues with Times. This mechanism of automatic restoration also applies to colors and line
width. The limit which triggers page breaks can be set with <A HREF='../doc/setautopagebreak.htm'>SetAutoPageBreak()</A>.
</BODY>
</HTML>
Binary file not shown.
@@ -0,0 +1,32 @@
from fpdf import FPDF
class PDF(FPDF):
def header(self):
# Logo
self.image('logo_pb.png',10,8,33)
# Arial bold 15
self.set_font('Arial','B',15)
# Move to the right
self.cell(80)
# Title
self.cell(30,10,'Title',1,0,'C')
# Line break
self.ln(20)
# Page footer
def footer(self):
# Position at 1.5 cm from bottom
self.set_y(-15)
# Arial italic 8
self.set_font('Arial','I',8)
# Page number
self.cell(0,10,'Page '+str(self.page_no())+'/{nb}',0,0,'C')
# Instanciation of inherited class
pdf=PDF()
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font('Times','',12)
for i in range(1,41):
pdf.cell(0,10,'Printing line number '+str(i),0,1)
pdf.output('tuto2.pdf','F')
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,67 @@
from fpdf import FPDF
title='20000 Leagues Under the Seas'
class PDF(FPDF):
def header(self):
#Arial bold 15
self.set_font('Arial','B',15)
#Calculate width of title and position
w=self.get_string_width(title)+6
self.set_x((210-w)/2)
#Colors of frame, background and text
self.set_draw_color(0,80,180)
self.set_fill_color(230,230,0)
self.set_text_color(220,50,50)
#Thickness of frame (1 mm)
self.set_line_width(1)
#Title
self.cell(w,9,title,1,1,'C',1)
#Line break
self.ln(10)
def footer(self):
#Position at 1.5 cm from bottom
self.set_y(-15)
#Arial italic 8
self.set_font('Arial','I',8)
#Text color in gray
self.set_text_color(128)
#Page number
self.cell(0,10,'Page '+str(self.page_no()),0,0,'C')
def chapter_title(self,num,label):
#Arial 12
self.set_font('Arial','',12)
#Background color
self.set_fill_color(200,220,255)
#Title
self.cell(0,6,"Chapter %d : %s"%(num,label),0,1,'L',1)
#Line break
self.ln(4)
def chapter_body(self,name):
#Read text file
txt=file(name).read()
#Times 12
self.set_font('Times','',12)
#Output justified text
self.multi_cell(0,5,txt)
#Line break
self.ln()
#Mention in italics
self.set_font('','I')
self.cell(0,5,'(end of excerpt)')
def print_chapter(self,num,title,name):
self.add_page()
self.chapter_title(num,title)
self.chapter_body(name)
pdf=PDF()
pdf.set_title(title)
pdf.set_author('Jules Verne')
pdf.print_chapter(1,'A RUNAWAY REEF','20k_c1.txt')
pdf.print_chapter(2,'THE PROS AND CONS','20k_c2.txt')
pdf.output('tuto3.pdf','F')
File diff suppressed because one or more lines are too long
@@ -0,0 +1,86 @@
from fpdf import *
class PDF(FPDF):
#Current column
col=0
#Ordinate of column start
y0=0
def header(self):
#Page header
self.set_font('Arial','B',15)
w=self.get_string_width(title)+6
self.set_x((210-w)/2.0)
self.set_draw_color(0,80,180)
self.set_fill_color(230,230,0)
self.set_text_color(220,50,50)
self.set_line_width(1)
self.cell(w,9,title,1,1,'C',1)
self.ln(10)
#Save ordinate
self.y0=self.get_y()
def footer(self):
#Page footer
self.set_y(-15)
self.set_font('Arial','I',8)
self.set_text_color(128)
self.cell(0,10,'Page '+str(self.page_no()),0,0,'C')
def set_col(self, col):
#Set position at a given column
self.col=col
x=10+col*65.0
self.set_left_margin(x)
self.set_x(x)
def accept_page_break(self):
#Method accepting or not automatic page break
if(self.col<2):
#Go to next column
self.set_col(self.col+1)
#Set ordinate to top
self.set_y(self.y0)
#Keep on page
return 0
else:
#Go back to first column
self.set_col(0)
#Page break
return 1
def chapter_title(self,num,label):
#Title
self.set_font('Arial','',12)
self.set_fill_color(200,220,255)
self.cell(0,6,"Chapter %d : %s"%(num,label),0,1,'L',1)
self.ln(4)
#Save ordinate
self.y0=self.get_y()
def chapter_body(self, fichier):
#Read text file
txt=file(fichier).read()
#Font
self.set_font('Times','',12)
#Output text in a 6 cm width column
self.multi_cell(60,5,txt)
self.ln()
#Mention
self.set_font('','I')
self.cell(0,5,'(end of excerpt)')
#Go back to first column
self.set_col(0)
def print_chapter(self,num,title,name):
#Add chapter
self.add_page()
self.chapter_title(num,title)
self.chapter_body(name)
pdf=PDF()
title='20000 Leagues Under the Seas'
pdf.set_title(title)
pdf.set_author('Jules Verne')
pdf.print_chapter(1,'A RUNAWAY REEF','20k_c1.txt')
pdf.print_chapter(2,'THE PROS AND CONS','20k_c2.txt')
pdf.output('tuto4.pdf','F')
File diff suppressed because one or more lines are too long
@@ -0,0 +1,82 @@
from fpdf import *
class PDF(FPDF):
#Load data
def load_data(self, name):
#Read file lines
data=[]
for line in file(name):
data += [line[:-1].split(';')]
return data
#Simple table
def basic_table(self,header,data):
#Header
for col in header:
self.cell(40,7,col,1)
self.ln()
#Data
for row in data:
for col in row:
self.cell(40,6,col,1)
self.ln()
#Better table
def improved_table(self,header,data):
#Column widths
w=[40,35,40,45]
#Header
for i in range(0,len(header)):
self.cell(w[i],7,header[i],1,0,'C')
self.ln()
#Data
for row in data:
self.cell(w[0],6,row[0],'LR')
self.cell(w[1],6,row[1],'LR')
self.cell(w[2],6,row[2],'LR',0,'R')
self.cell(w[3],6,row[3],'LR',0,'R')
self.ln()
#Closure line
self.cell(sum(w),0,'','T')
#Colored table
def fancy_table(self,header,data):
#Colors, line width and bold font
self.set_fill_color(255,0,0)
self.set_text_color(255)
self.set_draw_color(128,0,0)
self.set_line_width(.3)
self.set_font('','B')
#Header
w=[40,35,40,45]
for i in range(0,len(header)):
self.cell(w[i],7,header[i],1,0,'C',1)
self.ln()
#Color and font restoration
self.set_fill_color(224,235,255)
self.set_text_color(0)
self.set_font('')
#Data
fill=0
for row in data:
self.cell(w[0],6,row[0],'LR',0,'L',fill)
self.cell(w[1],6,row[1],'LR',0,'L',fill)
self.cell(w[2],6,row[2],'LR',0,'R',fill)
self.cell(w[3],6,row[3],'LR',0,'R',fill)
self.ln()
fill=not fill
self.cell(sum(w),0,'','T')
pdf=PDF()
#Column titles
header=['Country','Capital','Area (sq km)','Pop. (thousands)']
#Data loading
data=pdf.load_data('countries.txt')
pdf.set_font('Arial','',14)
pdf.add_page()
pdf.basic_table(header,data)
pdf.add_page()
pdf.improved_table(header,data)
pdf.add_page()
pdf.fancy_table(header,data)
pdf.output('tuto5.pdf','F')
File diff suppressed because one or more lines are too long
+101
View File
@@ -0,0 +1,101 @@
from fpdf import *
import re
class PDF(FPDF):
def __init__(self, orientation='P',unit='mm',format='A4'):
#Call parent constructor
FPDF.__init__(self,orientation,unit,format)
#Initialization
self.b=0
self.i=0
self.u=0
self.href=''
self.page_links={}
def write_html(self, html):
#HTML parser
html=html.replace("\n",' ')
a=re.split('<(.*?)>',html)
for i,e in enumerate(a):
if(i%2==0):
#Text
if(self.href):
self.put_link(self.href,e)
else:
self.write(5,e)
else:
#Tag
if(e[0]=='/'):
self.close_tag(e[1:].upper())
else:
#Extract attributes
attr={}
a2=e.split(' ')
tag=a2.pop(0).upper()
for v in a2:
a3 = re.findall('''^([^=]*)=["']?([^"']*)["']?''',v)[0]
if a3:
attr[a3[0].upper()]=a3[1]
self.open_tag(tag,attr)
def open_tag(self, tag,attr):
#Opening tag
if(tag=='B' or tag=='I' or tag=='U'):
self.set_style(tag,1)
if(tag=='A'):
self.href=attr['HREF']
if(tag=='BR'):
self.ln(5)
def close_tag(self, tag):
#Closing tag
if(tag=='B' or tag=='I' or tag=='U'):
self.set_style(tag,0)
if(tag=='A'):
self.href=''
def set_style(self, tag,enable):
#Modify style and select corresponding font
t = getattr(self,tag.lower())
if enable:
t+=1
else:
t+=-1
setattr(self,tag.lower(),t)
style=''
for s in ('B','I','U'):
if(getattr(self,s.lower())>0):
style+=s
self.set_font('',style)
def put_link(self, url, txt):
#Put a hyperlink
self.set_text_color(0,0,255)
self.set_style('U',1)
self.write(5,txt,url)
self.set_style('U',0)
self.set_text_color(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>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=PDF()
#First page
pdf.add_page()
pdf.set_font('Arial','',20)
pdf.write(5,'To find out what\'s new in self tutorial, click ')
pdf.set_font('','U')
link=pdf.add_link()
pdf.write(5,'here',link)
pdf.set_font('')
#Second page
pdf.add_page()
pdf.set_link(link)
pdf.image('logo.png',10,10,30,0,'','http:#www.fpdf.org')
pdf.set_left_margin(45)
pdf.set_font_size(14)
pdf.write_html(html)
pdf.output('tuto6.pdf','F')
@@ -0,0 +1,315 @@
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<TITLE>Aggiunta di nuovi fonts e supporto codifica</TITLE>
<LINK TYPE="text/css" REL="stylesheet" HREF="../fpdf.css">
</HEAD>
<BODY>
<H2>Aggiunta di nuovi fonts e supporto codifica</H2>
This tutorial explains how to use TrueType or Type1 fonts so that you are not limited to the standard
fonts any more. The other interest is that you can choose the font encoding, which allows you to
use other languages than the Western ones (the standard fonts having too few available characters).
<BR>
<BR>
There are two ways to use a new font: embedding it in the PDF or not. When a font is not
embedded, it is sought in the system. The advantage is that the PDF file is lighter; on the other
hand, if it is not available, a substitution font is used. So it is preferable to ensure that the
needed font is installed on the client systems. If the file is to be viewed by a large audience,
it is better to embed.
<BR>
<BR>
Adding a new font requires three steps for TrueTypes:
<UL>
<LI>Generation of the metric file (.afm)
<LI>Generation of the font definition file (.php)
<LI>Declaration of the font in the script
</UL>
For Type1, the first one is theoretically not necessary because the AFM file is usually shipped
with the font. In case you have only a metric file in PFM format, use the convertor available
<A HREF="http://www.fpdf.org/fr/dl.php?id=34">here</A>.
<H4 CLASS='st'>Generation of the metric file</H4>
The first step for a TrueType consists in generating the AFM file. A utility exists to do this
task: <A HREF="http://ttf2pt1.sourceforge.net" TARGET="_blank">ttf2pt1</A>. The Windows binary
is available <A HREF="http://www.fpdf.org/fr/dl.php?id=22">here</A>. The command line to use is
the following:
<BR>
<BR>
<TT>ttf2pt1 -a font.ttf font</TT>
<BR>
<BR>
For example, for Comic Sans MS Regular:
<BR>
<BR>
<TT>ttf2pt1 -a c:\windows\fonts\comic.ttf comic</TT>
<BR>
<BR>
Two files are created; the one we are interested in is comic.afm.
<H4 CLASS='st'>Generation of the font definition file</H4>
The second step consists in generating a PHP file containing all the information needed by FPDF;
in addition, the font file is compressed. To do this, a helper script is provided in the font/makefont/
directory of the package: makefont.php. It contains the following function:
<BR>
<BR>
<TT>MakeFont(<B>string</B> fontfile, <B>string</B> afmfile [, <B>string</B> enc [, <B>array</B> patch [, <B>string</B> type]]])</TT>
<BR>
<BR>
<TT><U>fontfile</U></TT>
<BLOCKQUOTE>
Path to the .ttf or .pfb file.
</BLOCKQUOTE>
<TT><U>afmfile</U></TT>
<BLOCKQUOTE>
Path to the .afm file.
</BLOCKQUOTE>
<TT><U>enc</U></TT>
<BLOCKQUOTE>
Name of the encoding to use. Default value: <TT>cp1252</TT>.
</BLOCKQUOTE>
<TT><U>patch</U></TT>
<BLOCKQUOTE>
Optional modification of the encoding. Empty by default.
</BLOCKQUOTE>
<TT><U>type</U></TT>
<BLOCKQUOTE>
Type of the font (<TT>TrueType</TT> or <TT>Type1</TT>). Default value: <TT>TrueType</TT>.
</BLOCKQUOTE>
<BR>
The first parameter is the name of the font file. The extension must be either .ttf or .pfb and
determines the font type. If you own a Type1 font in ASCII format (.pfa), you can convert it to
binary format with <A HREF="http://www.lcdf.org/~eddietwo/type/#t1utils" TARGET="_blank">t1utils</A>.
<BR>
If you don't want to embed the font, pass an empty string. In this case, type is given by the
<TT>type</TT> parameter.
<BR>
Note: in the case of a font with the same name as a standard one, for instance arial.ttf, it is
mandatory to embed. If you don't, Acrobat will use its own font.
<BR>
<BR>
The AFM file is the one previously generated.
<BR>
<BR>
The encoding defines the association between a code (from 0 to 255) and a character. The first
128 are fixed and correspond to ASCII; the following are variable. The encodings are stored in
.map files. Those available are:
<UL>
<LI>cp1250 (Central Europe)
<LI>cp1251 (Cyrillic)
<LI>cp1252 (Western Europe)
<LI>cp1253 (Greek)
<LI>cp1254 (Turkish)
<LI>cp1255 (Hebrew)
<LI>cp1257 (Baltic)
<LI>cp1258 (Vietnamese)
<LI>cp874 (Thai)
<LI>ISO-8859-1 (Western Europe)
<LI>ISO-8859-2 (Central Europe)
<LI>ISO-8859-4 (Baltic)
<LI>ISO-8859-5 (Cyrillic)
<LI>ISO-8859-7 (Greek)
<LI>ISO-8859-9 (Turkish)
<LI>ISO-8859-11 (Thai)
<LI>ISO-8859-15 (Western Europe)
<LI>ISO-8859-16 (Central Europe)
<LI>KOI8-R (Russian)
<LI>KOI8-U (Ukrainian)
</UL>
Of course, the font must contain the characters corresponding to the chosen encoding.
<BR>
In the particular case of a symbolic font (that is to say which does not contain letters, such
as Symbol or ZapfDingbats), pass an empty string.
<BR>
The encodings which begin with cp are those used by Windows; Linux systems usually use ISO.
<BR>
Remark: the standard fonts use cp1252.
<BR>
<BR>
The fourth parameter gives the possibility to alter the encoding. Sometimes you may want to add
some characters. For instance, ISO-8859-1 does not contain the euro symbol. To add it at position
164, pass <TT>array(164=>'Euro')</TT>.
<BR>
<BR>
The last parameter is used to give the type of the font in case it is not embedded (that is to
say the first parameter is empty).
<BR>
<BR>
After you have called the function (create a new file for this and include makefont.php, or
simply add the call directly inside), a .php file is created, with the same name as the .afm one.
You may rename it if you wish. If the case of embedding, the font file is compressed and gives a
second file with .z as extension (except if the compression function is not available, it
requires zlib). You may rename it too, but in this case you have to alter the variable <TT>$file</TT>
in the .php file accordingly.
<BR>
<BR>
Example:
<BR>
<BR>
<TT>MakeFont('c:\\windows\\fonts\\comic.ttf','comic.afm','cp1252');</TT>
<BR>
<BR>
which gives the files comic.php and comic.z.
<BR>
<BR>
Then you have to copy the generated file(s) to the font directory. If the font file
could not be compressed, copy the .ttf or .pfb instead of the .z.
<H4 CLASS='st'>Declaration of the font in the script</H4>
The last step is the most simple. You just need to call the <A HREF='../doc/addfont.htm'>AddFont()</A> method. For instance:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>AddFont<font class="kw">(</font><font class="str">'Comic'</font><font class="kw">,</font><font class="str">''</font><font class="kw">,</font><font class="str">'comic.php'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
or simply:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>AddFont<font class="kw">(</font><font class="str">'Comic'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
And the font is now available (in regular and underlined styles), usable like the others. If we
had worked with Comic Sans MS Bold (comicbd.ttf), we would have put:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>AddFont<font class="kw">(</font><font class="str">'Comic'</font><font class="kw">,</font><font class="str">'B'</font><font class="kw">,</font><font class="str">'comicbd.php'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
<H4 CLASS='st'>Example</H4>
Let's now see a small complete example. The font used is Calligrapher, available at
<A HREF="http://www.abstractfonts.com/fonts/" TARGET="_blank">www.abstractfonts.com</A> (a site
offering numerous free TrueType fonts). The first step is the generation of the AFM file:
<BR>
<BR>
<TT>ttf2pt1 -a calligra.ttf calligra</TT>
<BR>
<BR>
which gives calligra.afm (and calligra.t1a that we can delete). Then we generate the definition
file:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
&lt;?php<br><font class="kw">require(</font><font class="str">'font/makefont/makefont.php'</font><font class="kw">);<br><br></font>MakeFont<font class="kw">(</font><font class="str">'calligra.ttf'</font><font class="kw">,</font><font class="str">'calligra.afm'</font><font class="kw">);<br></font>?&gt;
</font>
</code></NOBR></TD></TR></TABLE><P></P>
The function call gives the following report:
<BR>
<BR>
<B>Warning:</B> character Euro is missing<BR>
<B>Warning:</B> character Zcaron is missing<BR>
<B>Warning:</B> character zcaron is missing<BR>
<B>Warning:</B> character eth is missing<BR>
Font file compressed (calligra.z)<BR>
Font definition file generated (calligra.php)<BR>
<BR>
The euro character is not present in the font (it is too old). Three other characters are missing
too, but we are not interested in them anyway.
<BR>
We can now copy the two files to the font directory and write the script:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
&lt;?php<br><font class="kw">require(</font><font class="str">'fpdf.php'</font><font class="kw">);<br><br></font>$pdf<font class="kw">=new </font>FPDF<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>AddFont<font class="kw">(</font><font class="str">'Calligrapher'</font><font class="kw">,</font><font class="str">''</font><font class="kw">,</font><font class="str">'calligra.php'</font><font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>AddPage<font class="kw">();<br></font>$pdf<font class="kw">-&gt;</font>SetFont<font class="kw">(</font><font class="str">'Calligrapher'</font><font class="kw">,</font><font class="str">''</font><font class="kw">,</font>35<font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>Cell<font class="kw">(</font>0<font class="kw">,</font>10<font class="kw">,</font><font class="str">'Enjoy new fonts with FPDF!'</font><font class="kw">);<br></font>$pdf<font class="kw">-&gt;</font>Output<font class="kw">();<br></font>?&gt;
</font>
</code></NOBR></TD></TR></TABLE><P></P>
<SCRIPT>
<!--
if(document.location.href.indexOf('http:')==0)
{
document.write("<P CLASS='demo'><A HREF='tuto7.php' TARGET='_blank' CLASS='demo'>[Demo]</A></P>");
}
//-->
</SCRIPT>
<H4 CLASS='st'>About the euro symbol</H4>
The euro character is not present in all encodings, and is not always placed at the same position:
<BR>
<BR>
<STYLE>
TH {text-align:left; background:#E0EBFF}
TH, TD {padding-left:10px; padding-right:10px; border-bottom-width:0px; border-left-width:1px; border-right-width:0px; border-top-width:1px}
TR.alt0 {background:#FFFFEE}
TR.alt1 {background:#FFFFDF}
</STYLE>
<TABLE STYLE="margin-left:15px; border-style:outset" BORDER="2" CELLSPACING="0" CELLPADDING="2" BGCOLOR2="#FFFFEE">
<TR><TH CLASS="st">Encoding</TH><TH CLASS="st">Position</TH></TR>
<TR CLASS="alt0"><TD>cp1250</TD><TD>128<BR></TD></TR>
<TR CLASS="alt1"><TD>cp1251</TD><TD>136<BR></TD></TR>
<TR CLASS="alt0"><TD>cp1252</TD><TD>128<BR></TD></TR>
<TR CLASS="alt1"><TD>cp1253</TD><TD>128<BR></TD></TR>
<TR CLASS="alt0"><TD>cp1254</TD><TD>128<BR></TD></TR>
<TR CLASS="alt1"><TD>cp1255</TD><TD>128<BR></TD></TR>
<TR CLASS="alt0"><TD>cp1257</TD><TD>128<BR></TD></TR>
<TR CLASS="alt1"><TD>cp1258</TD><TD>128<BR></TD></TR>
<TR CLASS="alt0"><TD>cp874</TD><TD>128<BR></TD></TR>
<TR CLASS="alt1"><TD>ISO-8859-1</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt0"><TD>ISO-8859-2</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt1"><TD>ISO-8859-4</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt0"><TD>ISO-8859-5</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt1"><TD>ISO-8859-7</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt0"><TD>ISO-8859-9</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt1"><TD>ISO-8859-11</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt0"><TD>ISO-8859-15</TD><TD>164<BR></TD></TR>
<TR CLASS="alt1"><TD>ISO-8859-16</TD><TD>164<BR></TD></TR>
<TR CLASS="alt0"><TD>KOI8-R</TD><TD>absent<BR></TD></TR>
<TR CLASS="alt1"><TD>KOI8-U</TD><TD>absent<BR></TD></TR>
</TABLE>
<BR>
ISO-8859-1 is widespread but does not include the euro sign. If you need it, the simplest thing
to do is using cp1252 or ISO-8859-15 instead, which are nearly identical but contain the precious
symbol.
<BR>
As for ISO-8859-2, it is possible to use ISO-8859-16 instead, but it contains many differences.
It is therefore simpler to patch the encoding to add the symbol to it, as explained above. The
same is true for the other encodings.
<H4 CLASS='st'>Font synthesis under Windows</H4>
When a TrueType font is not available in a given style, Windows is able to synthesize it from the
regular version. For instance, there is no Comic Sans MS Italic, but it can be built from Comic
Sans MS Regular. This feature can be used in a PDF file, but unfortunately requires that the
regular font be present in the system (you must not embed it). Here is how to do it:
<UL>
<LI>Generate the definition file for the regular font without embedding (you may rename it to
reflect the desired style)
<LI>Open it and append to the variable <TT>$name</TT> a comma followed by the desired style
(<TT>Italic</TT>, <TT>Bold</TT> or <TT>BoldItalic</TT>)
</UL>
For instance, for the file comici.php:
<BR>
<BR>
<TT>$name='ComicSansMS,Italic';</TT>
<BR>
<BR>
It can then be used normally:
<BR>
<BR>
<TABLE WIDTH="100%" STYLE="color:#4040C0; border-style:ridge" BORDERCOLORLIGHT="#B0B0E0" BORDERCOLORDARK="#000000" BORDER="2" CELLPADDING=6 CELLSPACING=0 BGCOLOR="#F0F5FF"><TR><TD style="border-width:0px">
<NOBR><code><font color="#000000">
$pdf<font class="kw">-&gt;</font>AddFont<font class="kw">(</font><font class="str">'Comic'</font><font class="kw">,</font><font class="str">'I'</font><font class="kw">,</font><font class="str">'comici.php'</font><font class="kw">);</font><br>
</font>
</code></NOBR></TD></TR></TABLE><P></P>
<H4 CLASS='st'>Reducing the size of TrueType fonts</H4>
Font files are often quite voluminous (more than 100, even 200KB); this is due to the fact that
they contain the characters corresponding to many encodings. zlib compression reduces them but
they remain fairly big. A technique exists to reduce them further. It consists in converting the
font to the Type1 format with ttf2pt1 by specifying the encoding you are interested in; all other
characters will be discarded.
<BR>
For instance, the arial.ttf font shipped with Windows 98 is 267KB (it contains 1296 characters).
After compression it gives 147. Let's convert it to Type1 by keeping only cp1250 characters:
<BR>
<BR>
<TT>ttf2pt1 -b -L cp1250.map c:\windows\fonts\arial.ttf arial</TT>
<BR>
<BR>
The .map files are located in the font/makefont/ directory of the package. The command produces
arial.pfb and arial.afm. The arial.pfb file is only 35KB, and 30KB after compression.
<BR>
<BR>
It is possible to go even further. If you are interested only by a subset of the encoding (you
probably don't need all 217 characters), you can open the .map file and remove the lines you are
not interested in. This will reduce the file size accordingly.
</BODY>
</HTML>
@@ -0,0 +1,8 @@
from fpdf import *
pdf=FPDF()
pdf.add_font('Calligrapher','','calligra.py')
pdf.add_page()
pdf.set_font('Calligrapher','',35)
pdf.cell(0,10,'Enjoy new fonts with FPDF!')
pdf.output('tuto7.pdf','F')
Binary file not shown.
@@ -0,0 +1,74 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
from fpdf import FPDF
import sys
fn = 'unicode.pdf'
pdf = FPDF()
pdf.add_page()
# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu','','DejaVuSansCondensed.ttf',uni=True)
pdf.set_font('DejaVu','',14)
text = u"""
English: Hello World
Greek: Γειά σου κόσμος
Polish: Witaj świecie
Portuguese: Olá mundo
Russian: Здравствуй, Мир
Vietnamese: Xin chào thế giới
Arabic: مرحبا العالم
Hebrew: שלום עולם
"""
for txt in text.split('\n'):
pdf.write(8, txt)
pdf.ln(8)
# Add a Indic Unicode font (uses UTF-8)
# Supports: Bengali, Devanagari, Gujarati,
# Gurmukhi (including the variants for Punjabi)
# Kannada, Malayalam, Oriya, Tamil, Telugu, Tibetan
pdf.add_font('gargi', '', 'gargi.ttf', uni=True)
pdf.set_font('gargi', '', 14)
pdf.write(8, u'Hindi: नमस्ते दुनिया')
pdf.ln(20)
# Add a AR PL New Sung Unicode font (uses UTF-8)
# The Open Source Chinese Font (also supports others east-asia languages)
pdf.add_font('fireflysung','','fireflysung.ttf',uni=True)
pdf.set_font('fireflysung','',14)
pdf.write(8, u'Chinese: 你好世界\n')
pdf.write(8, u'Japanese: こんにちは世界\n')
pdf.ln(10)
# Add a Alee Unicode font (uses UTF-8)
# General purpose Hangul truetype fonts that Contain Korean syllable
# and Latin9 (iso8859-15) characters.
pdf.add_font('eunjin','','Eunjin.ttf',uni=True)
pdf.set_font('eunjin','',14)
pdf.write(8, u'Korean: 안녕하세요')
pdf.ln(20)
# Add a Fonts-TLWG (formerly ThaiFonts-Scalable) (uses UTF-8)
pdf.add_font('waree','','Waree.ttf',uni=True)
pdf.set_font('waree','',14)
pdf.write(8, u'Thai: สวัสดีชาวโลก')
pdf.ln(20)
# Select a standard font (uses windows-1252)
pdf.set_font('Arial','',14)
pdf.ln(10)
pdf.write(5, 'This is standard built-in font')
pdf.output(fn,'F')
import os
try:
os.startfile(fn)
except:
os.system("evince %s" % fn)