mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
dompdf page size in mm
This commit is contained in:
@@ -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 ?
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user