no-tcpdf, added barcode, qrcode libs

This commit is contained in:
Yuri Kuznetsov
2023-11-13 12:55:47 +02:00
parent 4c341344f2
commit d44a0c6243
16 changed files with 262 additions and 879 deletions
@@ -50,7 +50,7 @@ use Espo\Tools\Pdf\ZipContents;
class MailMergeGenerator
{
private const DEFAULT_ENGINE = 'Tcpdf';
private const DEFAULT_ENGINE = 'Dompdf';
private const ATTACHMENT_MAIL_MERGE_ROLE = 'Mail Merge';
private EntityManager $entityManager;
@@ -1,58 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('K_TCPDF_EXTERNAL_CONFIG', true);
define('K_TCPDF_CALLS_IN_HTML', true);
define('K_BLANK_IMAGE', '_blank.png');
define('PDF_PAGE_FORMAT', 'A4');
define('PDF_PAGE_ORIENTATION', 'P');
define('PDF_CREATOR', 'TCPDF');
define('PDF_AUTHOR', 'TCPDF');
define('PDF_UNIT', 'mm');
define('PDF_MARGIN_HEADER', 5);
define('PDF_MARGIN_FOOTER', 10);
define('PDF_MARGIN_TOP', 27);
define('PDF_MARGIN_BOTTOM', 25);
define('PDF_MARGIN_LEFT', 15);
define('PDF_MARGIN_RIGHT', 15);
define('PDF_FONT_NAME_MAIN', 'helvetica');
define('PDF_FONT_SIZE_MAIN', 10);
define('PDF_FONT_NAME_DATA', 'helvetica');
define('PDF_FONT_SIZE_DATA', 8);
define('PDF_FONT_MONOSPACED', 'courier');
define('PDF_IMAGE_SCALE_RATIO', 1.25);
define('HEAD_MAGNIFICATION', 1.1);
define('K_CELL_HEIGHT_RATIO', 1.25);
define('K_TITLE_MAGNIFICATION', 1.3);
define('K_SMALL_RATIO', 2/3);
define('K_THAI_TOPCHARS', true);
define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
define('K_TIMEZONE', 'UTC');
@@ -39,36 +39,7 @@
"today": "Today (date)",
"now": "Now (date-time)"
},
"fontFace": {
"aealarabiya": "AlArabiya",
"aefurat": "Aefurat",
"cid0cs": "CID-0 cs",
"cid0ct": "CID-0 ct",
"cid0jp": "CID-0 jp",
"cid0kr": "CID-0 kr",
"courier": "Courier",
"dejavusans": "DejaVu Sans",
"dejavusanscondensed": "DejaVu Sans Condensed",
"dejavusansextralight": "DejaVu Sans ExtraLight",
"dejavusansmono": "DejaVu Sans Mono",
"dejavuserif": "DejaVu Serif",
"dejavuserifcondensed": "DejaVu Serif Condensed",
"freemono": "FreeMono",
"freesans": "FreeSans",
"freeserif": "FreeSerif",
"helvetica": "Helvetica",
"hysmyeongjostdmedium": "Hysmyeongjostd Medium",
"kozgopromedium": "Kozgo Pro Medium",
"kozminproregular": "Kozmin Pro Regular",
"msungstdlight": "Msung Std Light",
"pdfacourier": "PDFA Courier",
"pdfahelvetica": "PDFA Helvetica",
"pdfasymbol": "PDFA Symbol",
"pdfatimes": "PDFA Times",
"stsongstdlight": "STSong Std Light",
"symbol": "Symbol",
"times": "Times"
}
"fontFace": {}
},
"tooltips": {
"footer": "Use {pageNumber} to print page number.",
@@ -1,40 +1,4 @@
{
"Tcpdf": {
"implementationClassNameMap": {
"entity": "Espo\\Tools\\Pdf\\Tcpdf\\TcpdfEntityPrinter",
"collection": "Espo\\Tools\\Pdf\\Tcpdf\\TcpdfCollectionPrinter"
},
"fontFaceList": [
"aealarabiya",
"aefurat",
"cid0cs",
"cid0ct",
"cid0jp",
"cid0kr",
"courier",
"dejavusans",
"dejavusanscondensed",
"dejavusansextralight",
"dejavusansmono",
"dejavuserif",
"dejavuserifcondensed",
"freemono",
"freesans",
"freeserif",
"helvetica",
"hysmyeongjostdmedium",
"kozgopromedium",
"kozminproregular",
"msungstdlight",
"pdfacourier",
"pdfahelvetica",
"pdfasymbol",
"pdfatimes",
"stsongstdlight",
"symbol",
"times"
]
},
"Dompdf": {
"implementationClassNameMap": {
"entity": "Espo\\Tools\\Pdf\\Dompdf\\EntityPrinter"
@@ -37,8 +37,9 @@ use Espo\Tools\Pdf\Data;
use Espo\Tools\Pdf\Params;
use Espo\Tools\Pdf\Template;
use TCPDF2DBarcode;
use TCPDFBarcode;
use Picqer\Barcode\BarcodeGeneratorSVG;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
class HtmlComposer
{
@@ -251,16 +252,17 @@ class HtmlComposer
if ($codeType === 'QRcode') {
$width = $data['width'] ?? 40;
$height = $data['height'] ?? 40;
$color = $data['color'] ?? [0, 0, 0];
//$color = $data['color'] ?? '#000';
$barcode = new TCPDF2DBarcode($value, $type);
$code = $barcode->getBarcodeSVGcode($width, $height, $color);
$options = new QROptions();
$encoded = base64_encode($code);
$options->outputType = QRCode::OUTPUT_MARKUP_SVG;
$code = (new QRCode($options))->render($value);
$css = "width: {$width}mm; height: {$height}mm;";
return "<img src=\"data:image/svg+xml;base64,{$encoded}\" style=\"{$css}\">";
return "<img src=\"$code\" style=\"$css\">";
}
if (!$type) {
@@ -271,10 +273,9 @@ class HtmlComposer
$width = $data['width'] ?? 60;
$height = $data['height'] ?? 30;
$color = $data['color'] ?? [0, 0, 0];
$color = $data['color'] ?? '#000';
$barcode = new TCPDFBarcode($value, $type);
$code = $barcode->getBarcodeSVGcode($width, $height, $color);
$code = (new BarcodeGeneratorSVG())->getBarcode($value, $type, 2, $height, $color);
$encoded = base64_encode($code);
+1 -1
View File
@@ -51,7 +51,7 @@ use Espo\Tools\Pdf\Jobs\RemoveMassFile;
class MassService
{
private const DEFAULT_ENGINE = 'Tcpdf';
private const DEFAULT_ENGINE = 'Dompdf';
private const ATTACHMENT_MASS_PDF_ROLE = 'Mass Pdf';
private const REMOVE_MASS_PDF_PERIOD = '1 hour';
+1 -1
View File
@@ -41,7 +41,7 @@ use Espo\Tools\Pdf\Data\DataLoaderManager;
class Service
{
private const DEFAULT_ENGINE = 'Tcpdf';
private const DEFAULT_ENGINE = 'Dompdf';
private EntityManager $entityManager;
private Acl $acl;
@@ -1,249 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Pdf\Tcpdf;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Json;
use Espo\Core\Htmlizer\TemplateRendererFactory;
use Espo\Core\Htmlizer\TemplateRenderer;
use Espo\ORM\Entity;
use Espo\Tools\Pdf\Template;
use Espo\Tools\Pdf\Data;
use Espo\Tools\Pdf\Params;
use Espo\Tools\Pdf\Tcpdf\Tcpdf;
class EntityProcessor
{
private string $fontFace = 'freesans';
private int $fontSize = 12;
private Config $config;
private TemplateRendererFactory $templateRendererFactory;
public function __construct(Config $config, TemplateRendererFactory $templateRendererFactory)
{
$this->config = $config;
$this->templateRendererFactory = $templateRendererFactory;
}
public function process(Tcpdf $pdf, Template $template, Entity $entity, Params $params, Data $data): void
{
$renderer = $this->templateRendererFactory
->create()
->setApplyAcl($params->applyAcl())
->setEntity($entity)
->setData($data->getAdditionalTemplateData());
$fontFace = $this->config->get('pdfFontFace', $this->fontFace);
$fontSize = $this->config->get('pdfFontSize', $this->fontSize);
if ($template->getFontFace()) {
$fontFace = $template->getFontFace();
}
if ($template->hasTitle()) {
$title = $this->replacePlaceholders($template->getTitle(), $entity);
$pdf->SetTitle($title);
}
$pdf->setFont($fontFace, '', $fontSize, '', true);
$pdf->setAutoPageBreak(true, $template->getBottomMargin());
$pdf->setMargins(
$template->getLeftMargin(),
$template->getTopMargin(),
$template->getRightMargin()
);
$pageOrientation = $template->getPageOrientation();
$pageFormat = $template->getPageFormat();
if ($pageFormat === 'Custom') {
$pageFormat = [
$template->getPageWidth(),
$template->getPageHeight(),
];
}
$pageOrientationCode = 'P';
if ($pageOrientation === 'Landscape') {
$pageOrientationCode = 'L';
}
if ($template->hasFooter()) {
$htmlFooter = $this->render($renderer, $template->getFooter());
$pdf->setFooterFont([$fontFace, '', $this->fontSize]);
$pdf->setFooterPosition($template->getFooterPosition());
$pdf->setFooterHtml($htmlFooter);
}
else {
$pdf->setPrintFooter(false);
}
if ($template->hasHeader()) {
$htmlHeader = $this->render($renderer, $template->getHeader());
$pdf->setHeaderFont([$fontFace, '', $this->fontSize]);
$pdf->setHeaderPosition($template->getHeaderPosition());
$pdf->setHeaderHtml($htmlHeader);
}
else {
$pdf->setPrintHeader(false);
}
$pdf->addPage($pageOrientationCode, $pageFormat);
$htmlBody = $this->render($renderer, $template->getBody());
$pdf->writeHTML($htmlBody, true, false, true, false, '');
}
private function render(TemplateRenderer $renderer, string $template): string
{
$html = $renderer->renderTemplate($template);
/** @var string */
return preg_replace_callback(
'/<barcodeimage data="([^"]+)"\/>/',
function ($matches) {
$dataString = $matches[1];
$data = json_decode(urldecode($dataString), true);
return $this->composeBarcodeTag($data);
},
$html
);
}
/**
*
* @param array<string, mixed> $data
* @return string
*/
private function composeBarcodeTag(array $data): string
{
$value = $data['value'] ?? null;
$codeType = $data['type'] ?? 'CODE128';
$typeMap = [
"CODE128" => 'C128',
"CODE128A" => 'C128A',
"CODE128B" => 'C128B',
"CODE128C" => 'C128C',
"EAN13" => 'EAN13',
"EAN8" => 'EAN8',
"EAN5" => 'EAN5',
"EAN2" => 'EAN2',
"UPC" => 'UPCA',
"UPCE" => 'UPCE',
"ITF14" => 'I25',
"pharmacode" => 'PHARMA',
"QRcode" => 'QRCODE,H',
];
if ($codeType === 'QRcode') {
$function = 'write2DBarcode';
$params = [
$value,
$typeMap[$codeType] ?? null, /** @phpstan-ignore-line */
'', '',
$data['width'] ?? 40,
$data['height'] ?? 40,
[
'border' => false,
'vpadding' => $data['padding'] ?? 2,
'hpadding' => $data['padding'] ?? 2,
'fgcolor' => $data['color'] ?? [0, 0, 0],
'bgcolor' => $data['bgcolor'] ?? false,
'module_width' => 1,
'module_height' => 1,
],
'N',
];
}
else {
$function = 'write1DBarcode';
$params = [
$value,
$typeMap[$codeType] ?? null,
'', '',
$data['width'] ?? 60,
$data['height'] ?? 30,
0.4,
[
'position' => 'S',
'border' => false,
'padding' => $data['padding'] ?? 0,
'fgcolor' => $data['color'] ?? [0, 0, 0],
'bgcolor' => $data['bgcolor'] ?? [255, 255, 255],
'text' => $data['text'] ?? true,
'font' => 'helvetica',
'fontsize' => $data['fontsize'] ?? 14,
'stretchtext' => 4,
],
'N',
];
}
$paramsString = urlencode(Json::encode($params));
return "<tcpdf method=\"{$function}\" params=\"{$paramsString}\" />";
}
private function replacePlaceholders(string $string, Entity $entity): string
{
$newString = $string;
$attributeList = ['name'];
foreach ($attributeList as $attribute) {
$value = (string) ($entity->get($attribute) ?? '');
$newString = str_replace('{$' . $attribute . '}', $value, $newString);
}
return $newString;
}
}
-223
View File
@@ -1,223 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Pdf\Tcpdf;
use TCPDF as TcpdfOriginal;
use Espo\Core\Utils\Util;
use TCPDF_STATIC;
use Espo\Core\Utils\Json;
class Tcpdf extends TcpdfOriginal
{
/**
* @var string
*/
protected $footerHtml = '';
/**
* @var string
*/
protected $headerHtml = '';
/**
* @var float|int
*/
protected $footerPosition = 15;
/**
* @var float|int
*/
protected $headerPosition = 10;
/**
* @var bool
*/
protected $useGroupNumbers = false;
public function serializeTCPDFtagParameters($data) /** @phpstan-ignore-line */
{
return urlencode(Json::encode($data));
}
protected function unserializeTCPDFtagParameters($data) /** @phpstan-ignore-line */
{
return json_decode(urldecode($data), true);
}
/**
* @param bool $value
* @return void
*/
public function setUseGroupNumbers($value)
{
$this->useGroupNumbers = $value;
}
/**
* @param string $html
* @return void
*/
public function setHeaderHtml($html)
{
$this->headerHtml = $html;
}
/**
* @param string $html
* @return void
*/
public function setFooterHtml($html)
{
$this->footerHtml = $html;
}
/**
* @param float $position
* @return void
*/
public function setFooterPosition($position)
{
$this->footerPosition = $position;
}
/**
* @param float $position
* @return void
*/
public function setHeaderPosition($position)
{
$this->headerPosition = $position;
}
/**
* @return void
*/
public function Header()
{
$this->SetY($this->headerPosition);
$html = $this->headerHtml;
$html = $this->setPageNumbers($html);
$this->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, '', 0, false);
}
/**
* @return void
*/
public function Footer()
{
$breakMargin = $this->getBreakMargin();
$autoPageBreak = $this->AutoPageBreak;
$this->SetAutoPageBreak(false, 0);
$this->SetY((-1) * $this->footerPosition);
$html = $this->footerHtml;
$html = $this->setPageNumbers($html);
$this->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, '', 0, false);
$this->SetAutoPageBreak($autoPageBreak, $breakMargin);
}
/**
* @param string $html
* @return string
*/
private function setPageNumbers($html): string {
if ($this->useGroupNumbers) {
$html = str_replace('{pageNumber}', '{{:png:}}', $html);
$html = str_replace('{pageAbsoluteNumber}', '{{:pnp:}}', $html);
/** @phpstan-ignore-next-line */
if ($this->isUnicodeFont()) {
$html = str_replace('{totalPageNumber}', '{{:ptg:}}', $html);
} else {
$html = str_replace('{totalPageNumber}', '{:ptg:}', $html);
}
} else {
$html = str_replace('{pageNumber}', '{{:pnp:}}', $html);
$html = str_replace('{pageAbsoluteNumber}', '{{:pnp:}}', $html);
/** @phpstan-ignore-next-line */
if ($this->isUnicodeFont()) {
$html = str_replace('{totalPageNumber}', '{{:ptp:}}', $html);
} else {
$html = str_replace('{totalPageNumber}', '{:ptp:}', $html);
}
}
return $html;
}
/**
* @param string $name
* @param string $dest
* @return string
* @throws \Exception
*/
public function Output($name = 'doc.pdf', $dest = 'I')
{
if ($dest === 'I' && !$this->sign && php_sapi_name() != 'cli') {
if ($this->state < 3) {
$this->Close();
}
/** @var string $name */
$name = preg_replace('/[\s]+/', '_', $name);
$name = Util::sanitizeFileName($name);
if (ob_get_contents()) {
$this->Error('Some data has already been output, can\'t send PDF file');
}
header('Content-Type: application/pdf');
if (headers_sent()) {
$this->Error('Some data has already been output to browser, can\'t send PDF file');
}
header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Disposition: inline; filename="'.$name.'"');
TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen);
return '';
}
return parent::Output($name, $dest);
}
}
@@ -1,69 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Pdf\Tcpdf;
use Espo\ORM\Collection;
use Espo\Tools\Pdf\CollectionPrinter;
use Espo\Tools\Pdf\Template;
use Espo\Tools\Pdf\Contents;
use Espo\Tools\Pdf\Data;
use Espo\Tools\Pdf\IdDataMap;
use Espo\Tools\Pdf\Params;
use Espo\Tools\Pdf\Tcpdf\Tcpdf;
class TcpdfCollectionPrinter implements CollectionPrinter
{
private EntityProcessor $entityProcessor;
public function __construct(EntityProcessor $entityProcessor)
{
$this->entityProcessor = $entityProcessor;
}
/**
* @param Collection<\Espo\ORM\Entity> $collection
*/
public function print(Template $template, Collection $collection, Params $params, IdDataMap $dataMap): Contents
{
$pdf = new Tcpdf();
$pdf->setUseGroupNumbers(true);
foreach ($collection as $entity) {
$pdf->startPageGroup();
$data = $dataMap->get($entity->getId()) ?? Data::create();
$this->entityProcessor->process($pdf, $template, $entity, $params, $data);
}
return new TcpdfContents($pdf);
}
}
@@ -1,73 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Pdf\Tcpdf;
use Espo\Tools\Pdf\Contents;
use Espo\Tools\Pdf\Tcpdf\Tcpdf;
use Psr\Http\Message\StreamInterface;
use GuzzleHttp\Psr7\Stream;
use RuntimeException;
class TcpdfContents implements Contents
{
private $pdf;
public function __construct(Tcpdf $pdf)
{
$this->pdf = $pdf;
}
public function getStream(): StreamInterface
{
$resource = fopen('php://temp', 'r+');
if ($resource === false) {
throw new RuntimeException("Could not open temp.");
}
fwrite($resource, $this->getString());
rewind($resource);
return new Stream($resource);
}
public function getString(): string
{
return $this->pdf->output('', 'S');
}
public function getLength(): int
{
return strlen($this->getString());
}
}
@@ -1,57 +0,0 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2023 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Tools\Pdf\Tcpdf;
use Espo\ORM\Entity;
use Espo\Tools\Pdf\EntityPrinter;
use Espo\Tools\Pdf\Template;
use Espo\Tools\Pdf\Contents;
use Espo\Tools\Pdf\Params;
use Espo\Tools\Pdf\Data;
use Espo\Tools\Pdf\Tcpdf\Tcpdf;
class TcpdfEntityPrinter implements EntityPrinter
{
private $entityProcessor;
public function __construct(EntityProcessor $entityProcessor)
{
$this->entityProcessor = $entityProcessor;
}
public function print(Template $template, Entity $entity, Params $params, Data $data): Contents
{
$pdf = new Tcpdf();
$this->entityProcessor->process($pdf, $template, $entity, $params, $data);
return new TcpdfContents($pdf);
}
}
@@ -31,7 +31,7 @@ define('views/template/fields/font-face', ['views/fields/enum'], function (Dep)
return Dep.extend({
setupOptions: function () {
var engine = this.getConfig().get('pdfEngine') || 'Tcpdf';
var engine = this.getConfig().get('pdfEngine') || 'Dompdf';
var fontFaceList = this.getMetadata().get([
'app', 'pdfEngines', engine, 'fontFaceList',
+3 -3
View File
@@ -30,7 +30,6 @@
"zordius/lightncandy": "dev-espo#v1.2.5e",
"composer/semver": "^3",
"spatie/async": "1.5.6",
"tecnickcom/tcpdf": "6.3.5",
"symfony/process": "6.0.*",
"symfony/http-foundation": "6.0.*",
"symfony/routing": "6.0.*",
@@ -48,7 +47,9 @@
"phpseclib/phpseclib": "^3.0",
"openspout/openspout": "^4.9",
"dompdf/dompdf": "^2.0",
"brick/phonenumber": "^0.5.0"
"brick/phonenumber": "^0.5.0",
"picqer/php-barcode-generator": "^2.4",
"chillerlan/php-qrcode": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^9",
@@ -74,7 +75,6 @@
"Espo\\Modules\\": "custom/Espo/Modules/"
},
"files": [
"application/Espo/Resources/defaults/tcpdf-config.php",
"application/Espo/Resources/defaults/class-aliases.php"
]
},
Generated
+230 -67
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d00cfc7a66d5f0fc733141d48f9eca16",
"content-hash": "9282cc67e31e0de81934dcbdefcad5e6",
"packages": [
{
"name": "async-aws/core",
@@ -249,6 +249,148 @@
},
"time": "2021-12-14T00:20:41+00:00"
},
{
"name": "chillerlan/php-qrcode",
"version": "4.3.4",
"source": {
"type": "git",
"url": "https://github.com/chillerlan/php-qrcode.git",
"reference": "2ca4bf5ae048af1981d1023ee42a0a2a9d51e51d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/2ca4bf5ae048af1981d1023ee42a0a2a9d51e51d",
"reference": "2ca4bf5ae048af1981d1023ee42a0a2a9d51e51d",
"shasum": ""
},
"require": {
"chillerlan/php-settings-container": "^2.1.4",
"ext-mbstring": "*",
"php": "^7.4 || ^8.0"
},
"require-dev": {
"phan/phan": "^5.3",
"phpunit/phpunit": "^9.5",
"setasign/fpdf": "^1.8.2"
},
"suggest": {
"chillerlan/php-authenticator": "Yet another Google authenticator! Also creates URIs for mobile apps.",
"setasign/fpdf": "Required to use the QR FPDF output."
},
"type": "library",
"autoload": {
"psr-4": {
"chillerlan\\QRCode\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kazuhiko Arase",
"homepage": "https://github.com/kazuhikoarase"
},
{
"name": "Smiley",
"email": "smiley@chillerlan.net",
"homepage": "https://github.com/codemasher"
},
{
"name": "Contributors",
"homepage": "https://github.com/chillerlan/php-qrcode/graphs/contributors"
}
],
"description": "A QR code generator. PHP 7.4+",
"homepage": "https://github.com/chillerlan/php-qrcode",
"keywords": [
"phpqrcode",
"qr",
"qr code",
"qrcode",
"qrcode-generator"
],
"support": {
"issues": "https://github.com/chillerlan/php-qrcode/issues",
"source": "https://github.com/chillerlan/php-qrcode/tree/4.3.4"
},
"funding": [
{
"url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4",
"type": "custom"
},
{
"url": "https://ko-fi.com/codemasher",
"type": "ko_fi"
}
],
"time": "2022-07-25T09:12:45+00:00"
},
{
"name": "chillerlan/php-settings-container",
"version": "2.1.4",
"source": {
"type": "git",
"url": "https://github.com/chillerlan/php-settings-container.git",
"reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/1beb7df3c14346d4344b0b2e12f6f9a74feabd4a",
"reference": "1beb7df3c14346d4344b0b2e12f6f9a74feabd4a",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.4 || ^8.0"
},
"require-dev": {
"phan/phan": "^5.3",
"phpunit/phpunit": "^9.5"
},
"type": "library",
"autoload": {
"psr-4": {
"chillerlan\\Settings\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Smiley",
"email": "smiley@chillerlan.net",
"homepage": "https://github.com/codemasher"
}
],
"description": "A container class for immutable settings objects. Not a DI container. PHP 7.4+",
"homepage": "https://github.com/chillerlan/php-settings-container",
"keywords": [
"PHP7",
"Settings",
"configuration",
"container",
"helper"
],
"support": {
"issues": "https://github.com/chillerlan/php-settings-container/issues",
"source": "https://github.com/chillerlan/php-settings-container"
},
"funding": [
{
"url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4",
"type": "custom"
},
{
"url": "https://ko-fi.com/codemasher",
"type": "ko_fi"
}
],
"time": "2022-07-05T22:32:14+00:00"
},
{
"name": "composer/semver",
"version": "3.0.0",
@@ -3334,6 +3476,93 @@
],
"time": "2023-03-05T17:13:09+00:00"
},
{
"name": "picqer/php-barcode-generator",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/picqer/php-barcode-generator.git",
"reference": "4cec18909dffd86e14beb69b1040f2520c2e1bb1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/picqer/php-barcode-generator/zipball/4cec18909dffd86e14beb69b1040f2520c2e1bb1",
"reference": "4cec18909dffd86e14beb69b1040f2520c2e1bb1",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": "^7.3|^8.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5"
},
"suggest": {
"ext-bcmath": "Barcode IMB (Intelligent Mail Barcode) needs bcmath extension",
"ext-gd": "For JPG and PNG generators, GD or Imagick is required",
"ext-imagick": "For JPG and PNG generators, GD or Imagick is required"
},
"type": "library",
"autoload": {
"psr-4": {
"Picqer\\Barcode\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "Nicola Asuni",
"email": "info@tecnick.com",
"homepage": "http://nicolaasuni.tecnick.com"
},
{
"name": "Casper Bakker",
"email": "info@picqer.com",
"homepage": "https://picqer.com"
}
],
"description": "An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.",
"homepage": "https://github.com/picqer/php-barcode-generator",
"keywords": [
"CODABAR",
"Code11",
"Code93",
"EAN13",
"KIX",
"KIXCODE",
"MSI",
"POSTNET",
"Pharma",
"Standard 2 of 5",
"barcode",
"barcode generator",
"code128",
"code39",
"ean",
"html",
"jpeg",
"jpg",
"php",
"png",
"svg",
"upc"
],
"support": {
"issues": "https://github.com/picqer/php-barcode-generator/issues",
"source": "https://github.com/picqer/php-barcode-generator/tree/v2.4.0"
},
"funding": [
{
"url": "https://github.com/casperbakker",
"type": "github"
}
],
"time": "2023-09-16T08:58:52+00:00"
},
{
"name": "psr/cache",
"version": "1.0.1",
@@ -6057,72 +6286,6 @@
],
"time": "2021-03-23T23:28:01+00:00"
},
{
"name": "tecnickcom/tcpdf",
"version": "6.3.5",
"source": {
"type": "git",
"url": "https://github.com/tecnickcom/TCPDF.git",
"reference": "19a535eaa7fb1c1cac499109deeb1a7a201b4549"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/tecnickcom/TCPDF/zipball/19a535eaa7fb1c1cac499109deeb1a7a201b4549",
"reference": "19a535eaa7fb1c1cac499109deeb1a7a201b4549",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"autoload": {
"classmap": [
"config",
"include",
"tcpdf.php",
"tcpdf_parser.php",
"tcpdf_import.php",
"tcpdf_barcodes_1d.php",
"tcpdf_barcodes_2d.php",
"include/tcpdf_colors.php",
"include/tcpdf_filters.php",
"include/tcpdf_font_data.php",
"include/tcpdf_fonts.php",
"include/tcpdf_images.php",
"include/tcpdf_static.php",
"include/barcodes/datamatrix.php",
"include/barcodes/pdf417.php",
"include/barcodes/qrcode.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-only"
],
"authors": [
{
"name": "Nicola Asuni",
"email": "info@tecnick.com",
"role": "lead"
}
],
"description": "TCPDF is a PHP class for generating PDF documents and barcodes.",
"homepage": "http://www.tcpdf.org/",
"keywords": [
"PDFD32000-2008",
"TCPDF",
"barcodes",
"datamatrix",
"pdf",
"pdf417",
"qrcode"
],
"support": {
"issues": "https://github.com/tecnickcom/TCPDF/issues",
"source": "https://github.com/tecnickcom/TCPDF/tree/6.3.5"
},
"time": "2020-02-14T14:20:12+00:00"
},
{
"name": "webmozart/assert",
"version": "1.11.0",
+13
View File
@@ -35,6 +35,8 @@ class AfterUpgrade
{
public function run(Container $container): void
{
$config = $container->getByClass(Espo\Core\Utils\Config::class);
$configWriter = $container->getByClass(InjectableFactory::class)
->create(ConfigWriter::class);
@@ -43,6 +45,17 @@ class AfterUpgrade
'phoneNumberInternational' => false,
]);
if ($config->get('pdfEngine') === 'Tcpdf') {
$configWriter->set('pdfEngine', 'Dompdf');
if (php_sapi_name() === 'cli') {
echo "Important. The 'Tcpdf' PDF engine has been removed from EspoCRM. " .
"Now PDF printing is handled by the 'Dompdf' engine. " .
"If you would like to continue using the 'Tcpdf', download and install a free extension: {link}. " .
"After that, set 'Tcpdf' at Administration > Settings > PDF Engine.";
}
}
$configWriter->save();
}
}