-
-
Notifications
You must be signed in to change notification settings - Fork 177
Description
So this is a strange problem and here is my code:
`$pdf = new Fpdi();
$pdf->AddPage($audit->getCertificateVersion()->getOrientation());
$pdf->setSourceFile($pdfLocation);
$page1 = $pdf->importPage(1);
$pdf->useTemplate($page1);
foreach ($audit->getCertificateTextItems() as $certificateTextItem) {
$pdf->SetFontSize(20);
$pdf->SetFont(ucfirst(strtolower($certificateTextItem->getCertificateTextPlacement()->getCertificateTextPlacementFont()->getName())));
$pdf->SetTextColor(
$certificateTextItem->getCertificateTextPlacement()->getR(),
$certificateTextItem->getCertificateTextPlacement()->getG(),
$certificateTextItem->getCertificateTextPlacement()->getB()
);
// Set position. We divide by an offset because the X/Y pos values against the certificate text placement are CSS PX values
// because they are set by a frontend interface
$x = ( $certificateTextItem->getCertificateTextPlacement()->getXPos() * (25.4 / 96) ) - SELF::XOFFSET;
$y = ( $certificateTextItem->getCertificateTextPlacement()->getYPos() * (25.4 / 96) ) + SELF::YOFFSET;
$pdf->SetXY(
$x,
$y
);
// Add data to position
$pdf->Write(0, $certificateTextItem->getText());
$pdf->SetXY(0, 0);
}`
This code will always fail with:
{ "error": { "code": 500, "message": "Internal Server Error", "exception": [ { "message": "Notice: Trying to access array offset on value of type null", "class": "ErrorException", "trace": [ { "namespace": "", "short_class": "", "class": "", "type": "", "function": "", "file": "/var/www/html/vendor/setasign/fpdf/fpdf.php", "line": 530, "args": [] }, { "namespace": "", "short_class": "FPDF", "class": "FPDF", "type": "->", "function": "SetFontSize", "file": "/var/www/html/vendor/setasign/fpdi/src/FpdfTplTrait.php", "line": 403, "args": [ [ "integer", 20 ] ] }, { "namespace": "setasign\\Fpdi", "short_class": "FpdfTpl", "class": "setasign\\Fpdi\\FpdfTpl", "type": "->", "function": "SetFontSize", "file": "/var/www/html/src/Controller/CertificateGenerator/CertificateGenerator.php", "line": 28, "args": [ [ "integer", 20 ] ] }, { "namespace": "App\\Controller\\CertificateGenerator", "short_class": "CertificateGenerator", "class": "App\\Controller\\CertificateGenerator\\CertificateGenerator", "type": "->", "function": "generate", "file": "/var/www/html/src/Controller/Certificate/Rest/CertificateRestController.php", "line": 54, "args": [ [ "object", "App\\Entity\\Audit\\Audit" ] ] }, { "namespace": "App\\Controller\\Certificate\\Rest", "short_class": "CertificateRestController", "class": "App\\Controller\\Certificate\\Rest\\CertificateRestController", "type": "->", "function": "downloadAction", "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php", "line": 158, "args": [ [ "string", "2" ] ] }, { "namespace": "Symfony\\Component\\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\\Component\\HttpKernel\\HttpKernel", "type": "->", "function": "handleRaw", "file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php", "line": 80, "args": [ [ "object", "Symfony\\Component\\HttpFoundation\\Request" ], [ "integer", 1 ] ] }, { "namespace": "Symfony\\Component\\HttpKernel", "short_class": "HttpKernel", "class": "Symfony\\Component\\HttpKernel\\HttpKernel", "type": "->", "function": "handle", "file": "/var/www/html/vendor/symfony/http-kernel/Kernel.php", "line": 201, "args": [ [ "object", "Symfony\\Component\\HttpFoundation\\Request" ], [ "integer", 1 ], [ "boolean", true ] ] }, { "namespace": "Symfony\\Component\\HttpKernel", "short_class": "Kernel", "class": "Symfony\\Component\\HttpKernel\\Kernel", "type": "->", "function": "handle", "file": "/var/www/html/public/index.php", "line": 36, "args": [ [ "object", "Symfony\\Component\\HttpFoundation\\Request" ] ] } ] } ] } }
Unless I use $pdf->SetFontSize(12). If I use anything higher or lower than 12, the above error happens