Tag-based formatting


Author: Pascal Morin
License: Free for non-commercial use


This extension lets you display several paragraphs inside a frame. The use of tags allows to change the font, the style (bold, italic, underline), the size, and the color of characters. You can also use indentation and bullets.

To do this, 2 methods are available:

- The first one to define your tags:

SetStyle(string tag, string family, string style, int size, string color [, int indent [, string bullet]])

tag: name of the tag
family: family of the font
style: N (normal) or combination of B, I, U
size: size
color: color (comma-separated RGB components)
indent: to be specified for the paragraph tag; indents the first line by the indicated value
bullet : character to use for bullets (typically chr(149)) ; must be used in conjunction with indent

It is possible to use empty strings or null values, except for the paragraph tag. The values are obtained by inheritance; for instance, with <p><u>, the non-specified values of <u> are replaced by those from <p>.

- The second one to output text:

WriteTag(float w, float h, string txt [, int border [, string align [, int fill [, mixed padding]]]])

w: width of the line (0 to go from one margin to the other)
h: height of a line
txt: text to display - must have at least one tag at beginning and end to delimit a paragraph
border: 0 for none, 1 to have a border (default value: 0)
align: justification of text: L, R, C or J (default value: J)
fill: 0 for none, 1 for background filling (default value: 0)
padding: either a numerical value or a string of the form "left,top,bottom,right" with 2, 3 or 4 specified values (default value: 0)


This example is the beginning of "Little Red Riding Hood" by Charles Perrault. Specific styles are applied to names of persons, of places, and to verbs.

$pdf=new PDF_WriteTag();

// Stylesheet

// Title
$txt="<h1>Le petit chaperon rouge</h1>";


// Text
<p>Il <vb>était</vb> une fois <pers>une petite fille</pers> de <place>village</place>, 
la plus jolie qu'on <vb>eût su voir</vb>: <pers>sa mère</pers> en <vb>était</vb> 
folle, et <pers>sa mère grand</pers> plus folle encore. Cette <pers>bonne femme</pers> 
lui <vb>fit faire</vb> un petit chaperon rouge, qui lui <vb>seyait</vb> si bien 
que par tout on <vb>l'appelait</vb> <pers>le petit Chaperon rouge</pers>.</p> 

<p>Un jour <pers>sa mère</pers> <vb>ayant cuit</vb> et <vb>fait</vb> des galettes, 
<vb>lui dit</vb>: « <vb>Va voir</vb> comment <vb>se porte</vb> <pers>la mère-grand</pers>; 
car on <vb>m'a dit</vb> qu'elle <vb>était</vb> malade: <vb>porte-lui</vb> une 
galette et ce petit pot de beurre. »</p>
<p><pers>Le petit Chaperon rouge</pers> <vb>partit</vb> aussitôt pour <vb>aller</vb> 
chez <pers>sa mère-grand</pers>, qui <vb>demeurait</vb> dans <place>un autre village</place>. 
En passant dans <place>un bois</place>, elle <vb>rencontra</vb> compère <pers>le 
Loup</pers>, qui <vb>eut bien envie</vb> de <vb>la manger</vb>; mais il <vb>n'osa</vb> 
à cause de quelques <pers>bûcherons</pers> qui <vb>étaient</vb> dans 
<place>la forêt</place>.</p>



// Signature
$txt="<a href='http://www.pascal-morin.net'>Done by Pascal MORIN</a>";

View the result here.