1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
<?php
// 00.
// PRE-REQUIREMENTS ------------------------------------------------------------
// -*- PRINT_MODE is defined
// -*- $items[] array is defined and filled with data
// -*- RENDER_COVER is defined (optional)
// test requirements:
// echo "items: "; print_r($items); echo "\n---\nformaray: "; print_r($formARRAY); die();
// 01.
// INITIALIZE PRINTING ---------------------------------------------------------
// include library
// extend Header/Footer
////////////////////////////////////////////////////////////////////////////////
if (!defined("PRINT_MODE")) {
$deny = array(
'head' => "Σφάλμα κλήσης!",
'message' => "<p>Η διαδικασία έχει κληθεί με λάθος τρόπο ή μέθοδο.<p>
<p>Αν έχετε φτάσει σε αυτή τη σελίδα χρησιμοποιώντας μια αυτοματοποιημένη εργασία, παρακαλώ επικοινωνήστε με τον διαχειριστή της εφαρμογής.</p>"
);
include("includes/ui-message.php");
die();
}
// Include the main TCPDF library (search for installation path).
require_once('library/TCPDF/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
// $image_file = K_PATH_IMAGES.'logo_example.jpg';
// $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('ubuntuv14400', '', 9);
// Title
$this->Cell(0, 15, HEADER_TEXT, 0, false, 'R', 0, '', 0, false, 'M', 'M');
}
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('ubuntuv14400', '', 9);
// Page number
// $this->Cell(0, 15, '— '.$this->getAliasNumPage().' /'.$this->getAliasNbPages().' —', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 15, '— '.$this->getAliasNumPage().' —', 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// 02.
// Start PDF document ----------------------------------------------------------
// new object
// set attributes
// set defaults (fonts, sizes, margins, etc)
// draw cover-page
////////////////////////////////////////////////////////////////////////////////
// create new PDF document
if (PRINT_MODE == 'page')
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
else
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
// -----------------------------------------------------------------------------
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor(PDF_AUTHOR);
$pdf->SetTitle('Kallasha Project');
$pdf->SetSubject('Kallasha items');
$pdf->SetKeywords('Kallasha, File, Tradition');
// Construct Fonts (need only once; then font files are saved into fonts folder)
// $Ubuntu400font = TCPDF_FONTS::addTTFfont(dirname(__FILE__).'/library/TCPDF/fonts/pi-fonts/ubuntu-v14-400.ttf', 'TrueTypeUnicode', '', 32);
// $Ubuntu700font = TCPDF_FONTS::addTTFfont(dirname(__FILE__).'/library/TCPDF/fonts/pi-fonts/ubuntu-v14-700.ttf', 'TrueTypeUnicode', '', 32);
// if PAGE mode, remove default header/footer
// -----------------------------------------------------------------------------
if (PRINT_MODE == 'page') {
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
}
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
// if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
// require_once(dirname(__FILE__).'/lang/eng.php');
// $pdf->setLanguageArray($l);
// }
$tagvs = array('h1' => array(0 => array('h' => 1, 'n' => 3), 1 => array('h' => 1, 'n' => 2)),
'h2' => array(0 => array('h' => 1, 'n' => 2), 1 => array('h' => 1, 'n' => 1)),
'h3' => array(0 => array('h' => 1, 'n' => 2), 1 => array('h' => 1, 'n' => 1))
);
$pdf->setHtmlVSpace($tagvs);
// draw cover page
// -----------------------------------------------------------------------------
if (RENDER_COVER) {
$pdf->AddPage();
$pdf->SetFont('ubuntuv14400', '', 44, '', false);
$pdf->SetY(150);
$html = '<h1>'. COVER_TITLE .'</h1>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->SetFont('ubuntuv14400', '', 24, '', false);
$pdf->SetY(170);
$html = '<h3>'. COVER_SUB .'</h3>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->SetFont('ubuntuv14400', '', 11, '', false);
$pdf->SetY(200);
$html = '<p>'. COVER_CITY .', '. local_dt(time()) .'</p>';
$pdf->writeHTML($html, true, false, true, false, '');
}
// test page
// $pdf->AddPage();
// $pdf->SetFont('ubuntuv14400', '', 8, '', false);
// $pdf->writeHTML((print_r($items, true)), true, false, true, false, '');
// 03.
// render each item ------------------------------------------------------------
// parse sections, fields, values
// handle special fields
////////////////////////////////////////////////////////////////////////////////
// set font
$pdf->SetFont('ubuntuv14400', '', 9.5, '', false);
foreach ($items as $ki => $val) {
// add a page
$pdf->AddPage();
$text = '';
foreach ($formARRAY as $ks => $sect) {
$text .= '<h3>'. $sect->label . (($sect->section == 'identity') ? ' <span style="font-family:ubuntuv14700">#'.$val['identity'].'</span>' : '') .'</h3>';
foreach ($sect->childs as $key => $field) {
if ( ((isset($val[$field->nam])) && ($val[$field->nam] != '')) || ($field->nam == 'localname') ) { // for non-empty fields or localname
$fdata = parse_any($field->nam, $val[$field->nam]); // parse field + current value
$txt = $fdata['multi'] ? implode(", ", $fdata['value']) : $fdata['value']; // if array of values, implode values
if ($field->nam == 'ccode') { // handle CCODE
$cc = parse_ccode($val[$field->nam]); // get full CCODE label
// --- depricated: $piMore = $cc->local; // add kallassian local name
$localname = $cc->local; // add kallassian local name
}
// --- depricated: else $piMore = "";
// Special fields handling (other than default)
switch ($field->nam) {
case 'summary':
$text .= '<span style="color:#567; font-size:90%">'. $field->lab .': </span> '; // echo label
$text .= '<br>'. nl2br($txt) .'<br><br>';
break;
case 'itemid':
$text .= '<span style="color:#567; font-size:90%">'. $field->lab .': </span> '; // echo label
$text .= nl2br($txt) .' / '. $val['totalitems'] .'<br>';
case 'totalitems':
case 'identity':
// ignore ...
break;
case 'localname':
if (trim($txt) == "")
$txt = $localname;
default:
$text .= '<span style="color:#567; font-size:90%">'. $field->lab .': </span> '; // echo label
$text .= nl2br($txt) . '<br>'; // . (($piMore =='') ? '' : ' ('.$piMore.')') .'<br>';
}
}
}
}
// attach extra info
$sm = explode('---',$val['note']);
if (trim($sm[0]) != '') {
$text .= '<br><span style="color:#567; font-size:90%">Συμπληρωματική πληροφορία:</span><br>'. trim($sm[0]);
}
// prepare image html
$image = ($val['img'] == '') ? '' : ('<img src="'. $val['img'] .'"><br>');
$image .= ($val['img2'] == '') ? '' : ('<img src="'. $val['img2'] .'">');
// construct item HTML
// $html = '<h2>'. $val['identity'] .'</h2>
$html ='
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" width="59%">'. $text .'</td>
<td width="2%" align="center" valign="top"><span style="color:#eee">|</span></td>
<td width="39%">'. $image .'</td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_006.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
|