diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2026-07-12 15:51:52 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2026-07-12 15:51:52 +0300 |
| commit | 02608271bb2a9f3a65ed536984d306ee14b48e34 (patch) | |
| tree | 3f23ec48a694ec014e845c4f70d9b5f1c065403c /public/do-pdf.php | |
| download | kalassa-master.tar.gz kalassa-master.tar.bz2 kalassa-master.zip | |
Diffstat (limited to 'public/do-pdf.php')
| -rw-r--r-- | public/do-pdf.php | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/public/do-pdf.php b/public/do-pdf.php new file mode 100644 index 0000000..a3b5d00 --- /dev/null +++ b/public/do-pdf.php @@ -0,0 +1,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 +//============================================================+ |
