How implement barryvdh(create multipage PDF) into job in Laravel?

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?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;
}
}
</code>
<code><?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; } } </code>
<?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 :/

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật