| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\PDF; |
| 4 |
|
| 5 |
use LAM\ImageUtils\ImageManipulationFactory; |
| 6 |
use TCPDF; |
| 7 |
|
| 8 |
/* |
| 9 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 10 |
Copyright (C) 2017 - 2026 Roland Gruber |
| 11 |
|
| 12 |
This program is free software; you can redistribute it and/or modify |
| 13 |
it under the terms of the GNU General Public License as published by |
| 14 |
the Free Software Foundation; either version 2 of the License, or |
| 15 |
(at your option) any later version. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, |
| 18 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
GNU General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
along with this program; if not, write to the Free Software |
| 24 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
*/ |
| 26 |
|
| 27 |
/** |
| 28 |
* LDAP Account Manager PDF printing library for TCPDF. |
| 29 |
* |
| 30 |
* @author Roland Gruber |
| 31 |
* @package PDF |
| 32 |
*/ |
| 33 |
|
| 34 |
/** PDF generator class */ |
| 35 |
include_once(__DIR__ . "/3rdParty/tcpdf/tcpdf.php"); |
| 36 |
/** image manipulation */ |
| 37 |
include_once(__DIR__ . "/imageutils.inc"); |
| 38 |
|
| 39 |
class LAMTCPDF extends TCPDF { |
| 40 |
|
| 41 |
/** |
| 42 |
* @var PDFStructure structure |
| 43 |
*/ |
| 44 |
private $structure; |
| 45 |
|
| 46 |
/** |
| 47 |
* @var string font name |
| 48 |
*/ |
| 49 |
private $fontName; |
| 50 |
|
| 51 |
/** |
| 52 |
* Constructor. |
| 53 |
* |
| 54 |
* @param PDFStructure $structure PDF structure |
| 55 |
* @param string $fontName font name |
| 56 |
*/ |
| 57 |
public function __construct($structure, $fontName) { |
| 58 |
parent::__construct(); |
| 59 |
$this->structure = $structure; |
| 60 |
$this->fontName = $fontName; |
| 61 |
$this->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); |
| 62 |
$this->SetMargins(10, 35, 10); |
| 63 |
// generic PDF information |
| 64 |
$this->setTitle($this->structure->getTitle()); |
| 65 |
$this->setCreator("LDAP Account Manager"); |
| 66 |
$this->setAuthor("LDAP Account Manager"); |
| 67 |
// footer |
| 68 |
$this->setPrintFooter(true); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* {@inheritDoc} |
| 73 |
* @see TCPDF::Header() |
| 74 |
*/ |
| 75 |
public function Header(): void { |
| 76 |
$logoFile = $this->structure->getLogo(); |
| 77 |
$pdfStructurePersistenceManager = new PdfStructurePersistenceManager(); |
| 78 |
if (!empty($logoFile) && ($logoFile !== PDFStructure::NO_LOGO)) { |
| 79 |
$logoBinary = $pdfStructurePersistenceManager->getPdfLogoBinary($_SESSION['config']->getName(), $logoFile); |
| 80 |
if (!empty($logoBinary)) { |
| 81 |
$imageConverter = ImageManipulationFactory::getImageManipulator($logoBinary); |
| 82 |
$imageConverter->convertToJpeg(); |
| 83 |
$this->Image('@' . $imageConverter->getImageData(), 10, 10, 0, 15, 'JPG', '', 'T'); |
| 84 |
} |
| 85 |
else { |
| 86 |
logNewMessage(LOG_ERR, 'Unable to read PDF logo ' . $logoFile); |
| 87 |
$this->SetY(10); |
| 88 |
} |
| 89 |
} |
| 90 |
else { |
| 91 |
$this->SetY(10); |
| 92 |
} |
| 93 |
$this->SetFont($this->fontName, '', 20); |
| 94 |
$this->Cell(0, 15, $this->structure->getTitle(), 0, 1, 'R', false, '', 0, false, 'M'); |
| 95 |
//set folding marks |
| 96 |
if ($this->structure->getFoldingMarks() == PDFStructure::FOLDING_STANDARD) { |
| 97 |
$this->SetLineWidth(0.2); |
| 98 |
$foldingMarks = [97, 202]; |
| 99 |
foreach ($foldingMarks as $mark) { |
| 100 |
$this->Line(0, $mark, 5, $mark); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* {@inheritDoc} |
| 107 |
* @see TCPDF::Footer() |
| 108 |
*/ |
| 109 |
public function Footer(): void { |
| 110 |
$this->SetY(-15); |
| 111 |
$this->SetFont($this->fontName, '', LAMPDF_FONT_SIZE); |
| 112 |
$footerText = _("This document was automatically created by LDAP Account Manager") . ' (' . getFormattedTime('Y-m-d H:i:s T') . ')'; |
| 113 |
$this->Cell(0, 10, $footerText, 0, 0, 'C'); |
| 114 |
} |
| 115 |
|
| 116 |
} |