Add-On Tag-based formatting
Informations
Author:Pascal MorinLicense: Free for non-commercial use
Description
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 tagfamily
: family of the fontstyle
: N (normal) or combination of B, I, Usize
: sizecolor
: color (comma-separated RGB components)indent
: to be specified for the paragraph tag; indents the first line by the indicated valuebullet
: character to use for bullets (typically chr(149)
) ; must be used in conjunction with indentIt 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 linetxt
: text to display - must have at least one tag at beginning and end to delimit
a paragraphborder
: 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)
Example
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.<?php
require('WriteTag.php');
$pdf=new PDF_WriteTag();
$pdf->SetMargins(30, 15, 25);
$pdf->SetFont('courier', '', 12);
$pdf->AddPage();
// Stylesheet
$pdf->SetStyle("p", "courier", "N", 12, "10, 100, 250", 15);
$pdf->SetStyle("h1", "times", "N", 18, "102, 0, 102", 0);
$pdf->SetStyle("a", "times", "BU", 9, "0, 0, 255");
$pdf->SetStyle("pers", "times", "I", 0, "255, 0, 0");
$pdf->SetStyle("place", "arial", "U", 0, "153, 0, 0");
$pdf->SetStyle("vb", "times", "B", 0, "102, 153, 153");
// Title
$txt="<h1>Le petit chaperon rouge</h1>";
$pdf->SetLineWidth(0.5);
$pdf->SetFillColor(255, 255, 204);
$pdf->SetDrawColor(102, 0, 102);
$pdf->WriteTag(0, 10, $txt, 1, "C", 1, 5);
$pdf->Ln(15);
// Text
$txt="
<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>
";
$pdf->SetLineWidth(0.1);
$pdf->SetFillColor(255, 255, 204);
$pdf->SetDrawColor(102, 0, 102);
$pdf->WriteTag(0, 10, $txt, 1, "J", 0, 7);
$pdf->Ln(5);
// Signature
$txt="<a href='http://www.pascal-morin.net'>Done by Pascal MORIN</a>";
$pdf->WriteTag(0, 10, $txt, 0, "R");
$pdf->Output();
?>