Subversion Repositories Applications.annuaire

Rev

Rev 296 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_063.php
4
// Begin       : 2010-09-29
5
// Last Update : 2010-10-05
6
//
7
// Description : Example 063 for TCPDF class
8
//               Text stretching and spacing (tracking/kerning)
9
//
10
// Author: Nicola Asuni
11
//
12
// (c) Copyright:
13
//               Nicola Asuni
14
//               Tecnick.com s.r.l.
15
//               Via Della Pace, 11
16
//               09044 Quartucciu (CA)
17
//               ITALY
18
//               www.tecnick.com
19
//               info@tecnick.com
20
//============================================================+
21
 
22
/**
23
 * Creates an example PDF TEST document using TCPDF
24
 * @package com.tecnick.tcpdf
25
 * @abstract TCPDF - Example: Text stretching and spacing (tracking/kerning)
26
 * @author Nicola Asuni
27
 * @copyright 2063-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
28
 * @link http://tcpdf.org
29
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
30
 * @since 2010-09-29
31
 */
32
 
33
require_once('../config/lang/eng.php');
34
require_once('../tcpdf.php');
35
 
36
// create new PDF document
37
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
38
 
39
// set document information
40
$pdf->SetCreator(PDF_CREATOR);
41
$pdf->SetAuthor('Nicola Asuni');
42
$pdf->SetTitle('TCPDF Example 063');
43
$pdf->SetSubject('TCPDF Tutorial');
44
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
45
 
46
// set default header data
47
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 063', PDF_HEADER_STRING);
48
 
49
// set header and footer fonts
50
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
51
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
52
 
53
// set default monospaced font
54
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
55
 
56
//set margins
57
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
58
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
59
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
60
 
61
//set auto page breaks
62
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
63
 
64
//set image scale factor
65
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
66
 
67
//set some language-dependent strings
68
$pdf->setLanguageArray($l);
69
 
70
// ---------------------------------------------------------
71
 
72
// set font
73
$pdf->SetFont('helvetica', 'B', 16);
74
 
75
// add a page
76
$pdf->AddPage();
77
 
78
$pdf->Write(0, 'Example of Text Stretching and Spacing (tracking/kerning)', '', 0, 'L', true, 0, false, false, 0);
79
$pdf->Ln(5);
80
 
81
// create several cells to display all cases of stretching and kerning combinations.
82
 
83
$fonts = array('times', 'dejavuserif');
84
$alignments = array('L' => 'LEFT', 'C' => 'CENTER', 'R' => 'RIGHT', 'J' => 'JUSTIFY');
85
 
86
 
87
// Test all cases using direct stretching/spacing methods
88
foreach ($fonts as $fkey => $font) {
89
	$pdf->SetFont($font, '', 14);
90
	foreach ($alignments as $align_mode => $align_name) {
91
		for ($stretching = 90; $stretching <= 110; $stretching += 10) {
92
			for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {
93
				$pdf->setFontStretching($stretching);
94
				$pdf->setFontSpacing($spacing);
95
				$txt = $align_name.' | Stretching = '.$stretching.'% | Spacing = '.sprintf('%+.3F', $spacing).'mm';
96
				$pdf->Cell(0, 0, $txt, 1, 1, $align_mode);
97
			}
98
		}
99
	}
100
	$pdf->AddPage();
101
}
102
 
103
 
104
// Test all cases using CSS stretching/spacing properties
105
foreach ($fonts as $fkey => $font) {
106
	$pdf->SetFont($font, '', 11);
107
	foreach ($alignments as $align_mode => $align_name) {
108
		for ($stretching = 90; $stretching <= 110; $stretching += 10) {
109
			for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {
110
				$html = '<span style="font-stretch:'.$stretching.'%;letter-spacing:'.$spacing.'mm;"><span style="color:red;">'.$align_name.'</span> | <span style="color:green;">Stretching = '.$stretching.'%</span> | <span style="color:blue;">Spacing = '.sprintf('%+.3F', $spacing).'mm</span><br />Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus. Phasellus quis velit velit, non condimentum quam. Sed neque urna, ultrices ac volutpat vel, laoreet vitae augue. Sed vel velit erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</span>';
111
				$pdf->writeHTMLCell(0, 0, '', '', $html, 1, 1, false, true, $align_mode, false);
112
			}
113
		}
114
		if (!(($fkey == 1) AND ($align_mode == 'J'))) {
115
			$pdf->AddPage();
116
		}
117
	}
118
}
119
 
120
 
121
// reset font stretching
122
$pdf->setFontStretching(100);
123
 
124
// reset font spacing
125
$pdf->setFontSpacing(0);
126
 
127
// ---------------------------------------------------------
128
 
129
//Close and output PDF document
130
$pdf->Output('example_063.pdf', 'I');
131
 
132
//============================================================+
133
// END OF FILE
134
//============================================================+