I have a problem and need some help on how to implement the Barryvdh DomPDF library or more specifically, how to use this library to create a multi-page PDF. My goal is to generate a PDF that consolidates multiple documents into one single multi-page PDF. Currently, the job ensures that multiple PDFs can be printed or generated sequentially, but each one is generated individually. However, I need to ensure that all these PDF files are generated into one single multi-page PDF. I have no idea how to achieve this in the job. Could someone assist me?
This is Laravel job for generating PDF
<?php
namespace ModulesStoreJobsItemProduct;
use AppModelsUser;
use AppJobsNodesCreatePDF;
use IlluminateBusBatchable;
use IlluminateBusQueueable;
use AppJobsNodesUserNotice;
use IlluminateSupportFacadesBus;
use AppLibrariesWebDocumentsLibrary;
use IlluminateQueueInteractsWithQueue;
use ModulesStoreModelsStoreItemProduct;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use BarryvdhDomPDFFacadePdf;
class StoreViewItemProductLabelJob extends WebDocumentsLibrary implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable;
/** @var array */
private $data;
/** @var User */
private $user;
private $appID;
private $options;
private $template;
private $download;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($data, $user, $appID, $download = true)
{
$this->data = $data;
$this->user = $user;
$this->appID = $appID;
$this->download = $download;
}
public function handle(): void
{
/** Data by id from Item product */
$this->data['store_item_product'] = StoreItemProduct::where('id', $this->data['id'])->first();
$this->data['store_item'] = $this->data['store_item_product']->store_item()->first();
$this->data['supplier'] = $this->data['store_item']->supplier()->first();
$this->data['materialproduct'] = $this->data['store_item_product']->materialproduct()->first();
$this->data['material'] = $this->data['materialproduct'] ? $this->data['materialproduct']->material()->first() : null;
/** Date and time */
$this->data['date'] = date('d/m/Y');
$this->data['time'] = date('H:i:s');
if (!empty($this->data)) {
$pathInfo = pathinfo($this->data['path']);
$filename = $pathInfo['filename'];
$pathInfo['filename'] = $filename;
$this->data['path'] = $pathInfo['dirname'] . '/' . $filename . '.' . $pathInfo['extension'];
/** Set template */
$this->setOptionsAndTemplate();
/** Create PDF with the unique filename */
Bus::chain([
new CreatePDF($this->data['path'], $this->data, $this->template, $this->options, 'hobs'),
new UserNotice(
$this->user,
"success",
__("purchases.document_was_generated", ["Object" => $filename]),
null,
["object" => "purchase", "download" => $this->download ? $this->data['path'] : null, "appID" => ($this->appID ?? null)]
)
])->dispatch();
}
}
/**
* Handle a job failure.
*
* @param Throwable $th
* @return void
*/
public function failed(Throwable $th): void
{
UserNotice::dispatch($this->user, "error", __("general.error"), $th->getMessage());
}
/** set and get template for eancode PDF */
public function setOptionsAndTemplate()
{
$this->options = [
'format' => ['101', '151'],
'margin_left' => 5,
'margin_right' => 5,
'margin_top' => 5,
'margin_bottom' => 5,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'L',
];
$this->template = "store::documents/store/item_product";
return $this->template;
}
}
I need to explain how to create multipage PDF in Laravel job :/