|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * SugarCRM Community Edition is a customer relationship management program developed by |
| 4 | + * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
| 5 | + * |
| 6 | + * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd. |
| 7 | + * Copyright (C) 2011 - 2021 SalesAgility Ltd. |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify it under |
| 10 | + * the terms of the GNU Affero General Public License version 3 as published by the |
| 11 | + * Free Software Foundation with the addition of the following permission added |
| 12 | + * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
| 13 | + * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
| 14 | + * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
| 19 | + * details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License along with |
| 22 | + * this program; if not, see http://www.gnu.org/licenses or write to the Free |
| 23 | + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 24 | + * 02110-1301 USA. |
| 25 | + * |
| 26 | + * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
| 27 | + * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
| 28 | + * |
| 29 | + * The interactive user interfaces in modified source and object code versions |
| 30 | + * of this program must display Appropriate Legal Notices, as required under |
| 31 | + * Section 5 of the GNU Affero General Public License version 3. |
| 32 | + * |
| 33 | + * In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
| 34 | + * these Appropriate Legal Notices must retain the display of the "Powered by |
| 35 | + * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
| 36 | + * reasonably feasible for technical reasons, the Appropriate Legal Notices must |
| 37 | + * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
| 38 | + */ |
| 39 | + |
| 40 | +namespace SuiteCRM\PDF\MPDF; |
| 41 | + |
| 42 | +if (!defined('sugarEntry') || !sugarEntry) { |
| 43 | + die('Not A Valid Entry Point'); |
| 44 | +} |
| 45 | + |
| 46 | +use mPDF; |
| 47 | +use SuiteCRM\PDF\PDFEngine; |
| 48 | + |
| 49 | +require_once __DIR__ . '/../../../modules/AOS_PDF_Templates/PDF_Lib/mpdf.php'; |
| 50 | + |
| 51 | +/** |
| 52 | + * Class MPDFEngine |
| 53 | + * @package SuiteCRM\PDF\MPDF |
| 54 | + */ |
| 55 | +class MPDFEngine extends PDFEngine |
| 56 | +{ |
| 57 | + /** |
| 58 | + * @var mPDF |
| 59 | + */ |
| 60 | + public $pdf; |
| 61 | + |
| 62 | + /** |
| 63 | + * MPDFEngine constructor. |
| 64 | + * @param mPDF|null $pdf |
| 65 | + */ |
| 66 | + public function __construct(mPDF $pdf = null) |
| 67 | + { |
| 68 | + @$this->pdf = $pdf ?? new mPDF(); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @param string $html |
| 73 | + * @param int $section 0=default; 1=headerCSS; 2=HTML body; 3=HTML parses; 4=HTML headers; |
| 74 | + * @param bool $init Leaves buffers, etc, in current state so that it can continue a block. |
| 75 | + * @param bool $close Clears and sets buffers to top level block. |
| 76 | + * @return void |
| 77 | + */ |
| 78 | + public function writeHTML(string $html, int $section = 0, bool $init = true, bool $close = true): void |
| 79 | + { |
| 80 | + @$this->pdf->WriteHTML($html, $section, $init, $close); |
| 81 | + |
| 82 | + if ($section === 1) { |
| 83 | + @$this->pdf->SetDefaultBodyCSS('background-color', '#FFFFFF'); |
| 84 | + unset($this->pdf->cssmgr->CSS['INPUT']['FONT-SIZE']); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @param string $name |
| 90 | + * @param string $destination |
| 91 | + * @return void|string |
| 92 | + */ |
| 93 | + public function outputPDF(string $name, string $destination): ?string |
| 94 | + { |
| 95 | + @$output = $this->pdf->Output($name, $destination); |
| 96 | + |
| 97 | + if (is_string($output)) { |
| 98 | + return $output; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @param string|array $html |
| 104 | + * @return void |
| 105 | + */ |
| 106 | + public function writeHeader(string $html): void |
| 107 | + { |
| 108 | + @$this->pdf->setHeader($html); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @param string|array $html |
| 113 | + * @return void |
| 114 | + */ |
| 115 | + public function writeFooter(string $html): void |
| 116 | + { |
| 117 | + @$this->pdf->setFooter($html); |
| 118 | + } |
| 119 | + |
| 120 | + public function writeBlankPage(): void |
| 121 | + { |
| 122 | + @$this->pdf->AddPage(); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * @param array $options |
| 127 | + * @return void |
| 128 | + */ |
| 129 | + public function configurePDF(array $options): void |
| 130 | + { |
| 131 | + $configOptions = [ |
| 132 | + 'mode' => $options['mode'] ?? '', |
| 133 | + 'page_size' => $options['page_size'] ?? 'A4', |
| 134 | + 'default_font_size' => $options['fontSize'] ?? 0, |
| 135 | + 'default_font' => $options['font'] ?? '', |
| 136 | + 'mgl' => $options['mgl'] ?? 15, |
| 137 | + 'mgr' => $options['mgr'] ?? 15, |
| 138 | + 'mgt' => $options['mgt'] ?? 16, |
| 139 | + 'mgb' => $options['mgb'] ?? 16, |
| 140 | + 'mgh' => $options['mgh'] ?? 9, |
| 141 | + 'mgf' => $options['mgf'] ?? 9, |
| 142 | + 'orientation' => $options['orientation'] ?? 'P' |
| 143 | + ]; |
| 144 | + |
| 145 | + @$this->pdf = new mPDF( |
| 146 | + $configOptions['mode'], |
| 147 | + $configOptions['page_size'], |
| 148 | + $configOptions['default_font_size'], |
| 149 | + $configOptions['default_font'], |
| 150 | + $configOptions['mgl'], |
| 151 | + $configOptions['mgr'], |
| 152 | + $configOptions['mgt'], |
| 153 | + $configOptions['mgb'], |
| 154 | + $configOptions['mgh'], |
| 155 | + $configOptions['mgf'], |
| 156 | + $configOptions['orientation'], |
| 157 | + ); |
| 158 | + |
| 159 | + @$this->pdf->SetAutoFont(); |
| 160 | + } |
| 161 | +} |
0 commit comments