Hi,
situation :
i create qrCode with Endroid\QrCode library (github)
the result 'image/png' is saved as Attachment.
when try to print-to-pdf :
if engine is :
- dompdf : no result
- tcpdf : qrcode is printed.
so my solution was to create a new template helper "imageTagInline":
see doc how make a custome pdf helper.
certainly need more "control/throw error" but the base is here.
Just, we can create attachment with : 'contents' => $contents,
but we can't get the contents.. so it's why i use FileManager
situation :
i create qrCode with Endroid\QrCode library (github)
the result 'image/png' is saved as Attachment.
when try to print-to-pdf :
if engine is :
- dompdf : no result
- tcpdf : qrcode is printed.
so my solution was to create a new template helper "imageTagInline":
see doc how make a custome pdf helper.
certainly need more "control/throw error" but the base is here.
Just, we can create attachment with : 'contents' => $contents,
but we can't get the contents.. so it's why i use FileManager
PHP Code:
<?php
namespace Espo\Custom\TemplateHelpers;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\Log;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Htmlizer\Helper;
use Espo\Core\Htmlizer\Helper\Data;
use Espo\Core\Htmlizer\Helper\Result;
class ImageTagInline implements Helper
{
public function __construct(
private EntityManager $em,
private Log $log,
private FileManager $fileManager,
){}
public function render(Data $data): Result
{
$idAttachment = $data->getArgumentList()[0] ?? '';
$attachment = $this->em->getEntityById('Attachment', $idAttachment);
$width = $color = $data->getOption('width');
$height = $data->getOption('height');
$attributesPart = "";
if ($width) {
$attributesPart .= " width="" .strval($width) . """;
}
if ($height) {
$attributesPart .= " height="" .strval($height) . """;
}
//$contents = $attachment->get('contents'); DON'T WORK AS CREATE ATTACHMENT
$contents = $this->fileManager->getContents('data/upload/' .$idAttachment);
$type = $attachment->getType();
$image = base64_encode( $contents );
$html = "<img src="data:{$type};base64,{$image}"{$attributesPart}>";
return Result::createSafeString($html);
}
}
Comment