source: sipes/libraries/tcpdf/examples/example_063.php

stableversion-3.0
Last change on this file was 307d09d, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agregaron las librerias

  • Propiedad mode establecida a 100755
File size: 4.4 KB
Línea 
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 * @since 2010-09-29
28 */
29
30require_once('../config/lang/eng.php');
31require_once('../tcpdf.php');
32
33// create new PDF document
34$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
35
36// set document information
37$pdf->SetCreator(PDF_CREATOR);
38$pdf->SetAuthor('Nicola Asuni');
39$pdf->SetTitle('TCPDF Example 063');
40$pdf->SetSubject('TCPDF Tutorial');
41$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
42
43// set default header data
44$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 063', PDF_HEADER_STRING);
45
46// set header and footer fonts
47$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
48$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
49
50// set default monospaced font
51$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
52
53//set margins
54$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
55$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
56$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
57
58//set auto page breaks
59$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
60
61//set image scale factor
62$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
63
64//set some language-dependent strings
65$pdf->setLanguageArray($l);
66
67// ---------------------------------------------------------
68
69// set font
70$pdf->SetFont('helvetica', 'B', 16);
71
72// add a page
73$pdf->AddPage();
74
75$pdf->Write(0, 'Example of Text Stretching and Spacing (tracking/kerning)', '', 0, 'L', true, 0, false, false, 0);
76$pdf->Ln(5);
77
78// create several cells to display all cases of stretching and kerning combinations.
79
80$fonts = array('times', 'dejavuserif');
81$alignments = array('L' => 'LEFT', 'C' => 'CENTER', 'R' => 'RIGHT', 'J' => 'JUSTIFY');
82
83
84// Test all cases using direct stretching/spacing methods
85foreach ($fonts as $fkey => $font) {
86        $pdf->SetFont($font, '', 14);
87        foreach ($alignments as $align_mode => $align_name) {
88                for ($stretching = 90; $stretching <= 110; $stretching += 10) {
89                        for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {
90                                $pdf->setFontStretching($stretching);
91                                $pdf->setFontSpacing($spacing);
92                                $txt = $align_name.' | Stretching = '.$stretching.'% | Spacing = '.sprintf('%+.3F', $spacing).'mm';
93                                $pdf->Cell(0, 0, $txt, 1, 1, $align_mode);
94                        }
95                }
96        }
97        $pdf->AddPage();
98}
99
100
101// Test all cases using CSS stretching/spacing properties
102foreach ($fonts as $fkey => $font) {
103        $pdf->SetFont($font, '', 11);
104        foreach ($alignments as $align_mode => $align_name) {
105                for ($stretching = 90; $stretching <= 110; $stretching += 10) {
106                        for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {
107                                $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>';
108                                $pdf->writeHTMLCell(0, 0, '', '', $html, 1, 1, false, true, $align_mode, false);
109                        }
110                }
111                if (!(($fkey == 1) AND ($align_mode == 'J'))) {
112                        $pdf->AddPage();
113                }
114        }
115}
116
117
118// reset font stretching
119$pdf->setFontStretching(100);
120
121// reset font spacing
122$pdf->setFontSpacing(0);
123
124// ---------------------------------------------------------
125
126//Close and output PDF document
127$pdf->Output('example_063.pdf', 'I');
128
129//============================================================+
130// END OF FILE
131//============================================================+
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.