dompdf page size in mm

This commit is contained in:
Yuri Kuznetsov
2024-02-21 11:23:52 +02:00
parent ee294f889c
commit befd48d053
2 changed files with 37 additions and 1 deletions

View File

@@ -38,6 +38,8 @@ class DompdfInitializer
{
private string $defaultFontFace = 'DejaVu Sans';
private const PT = 2.83465;
public function __construct(
private Config $config
) {}
@@ -51,7 +53,7 @@ class DompdfInitializer
$pdf = new Dompdf($options);
$size = $template->getPageFormat() === Template::PAGE_FORMAT_CUSTOM ?
[0.0, 0.0, $template->getPageWidth(), $template->getPageHeight()] :
[0.0, 0.0, $template->getPageWidth() * self::PT, $template->getPageHeight() * self::PT] :
$template->getPageFormat();
$orientation = $template->getPageOrientation() === Template::PAGE_ORIENTATION_PORTRAIT ?

View File

@@ -29,7 +29,11 @@
use Espo\Core\Container;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Config\ConfigWriter;
use Espo\Entities\Template;
use Espo\ORM\EntityManager;
use Espo\Tools\Pdf\Template as PdfTemplate;
/** @noinspection PhpMultipleClassDeclarationsInspection */
class AfterUpgrade
@@ -44,5 +48,35 @@ class AfterUpgrade
]);
$configWriter->save();
$em = $container->getByClass(EntityManager::class);
$config = $container->getByClass(Config::class);
$this->updateTemplates($em, $config);
}
private function updateTemplates(EntityManager $entityManager, Config $config): void
{
if ($config->get('pdfEngine') !== 'Dompdf') {
return;
}
/** @var iterable<Template> $templates */
$templates = $entityManager->getRDBRepositoryByClass(Template::class)
->sth()
->where(['pageFormat' => PdfTemplate::PAGE_FORMAT_CUSTOM])
->find();
foreach ($templates as $template) {
$width = $template->get('pageWidth') ?? 0.0;
$height = $template->get('pageHeight') ?? 0.0;
$template->setMultiple([
'pageWidth' => $width / 2.83465,
'pageHeight' => $height / 2.83465,
]);
$entityManager->saveEntity($template);
}
}
}