Have you checked your error log? This mostly means that in your script something is referenced which is not defined in the context of, in this case, the job. This could for example be your globals, or perhaps your $pdf variable. Your error log should probably provide more details on this.
Nov 26, 2019
5
Level 9
laravel-dompdf queued job
I have an issue with dompdf and queued jobs. Any help on this topic is very welcome :)
When exporting a resource to pdf synchronously everything works as expected. As soon as I queue the job the following code doesn't work anymore and breaks the layout of my pdf:
<script type="text/php"> $GLOBALS['entity_page'][] = $pdf->get_page_number()-2; </script>
<script type="text/php">
$pdf->page_script('
if ($PAGE_NUM > 2) {
$font = $fontMetrics->getFont("Open Sans");
$current_page = $PAGE_NUM-2;
$total_pages = $PAGE_COUNT-2;
$text = "Seite $current_page von $total_pages";
$width = $fontMetrics->get_text_width($text, $font, 8) / 2;
$x = ($pdf->get_width() - $width) / 2;
$y = $pdf->get_height() - 35;
$pdf->text($x, $y, $text, $font, 8, array(0,0,0));
}
');
$GLOBALS["entity_val"] = 0;
$GLOBALS["entity_y"] = 120;
foreach ($GLOBALS['entity_page'] as $key => $val) {
$pdf->page_script('if($PAGE_NUM == 2){
$font = $fontMetrics->getFont("Open Sans");
$x = 550;
$y = $GLOBALS["entity_y"];
$pdf->text($x, $y, " Seite ".$GLOBALS["entity_page"][$GLOBALS["entity_val"]]."" , $font, 7, array(0, 0, 0, 1));
$GLOBALS["entity_y"] = $GLOBALS["entity_y"] +14.3;
$GLOBALS["entity_val"] = $GLOBALS["entity_val"] + 1;
}');
}
</script>
This code is supposed to build a table of contents. As I said everything works flawlessly when exporting synchronously. Does anybody have input on this?
Please or to participate in this conversation.