Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

delyn12's avatar

Get half of A4 Size

Good day everyone, Please I would like to ask if there is any tutorial I can watch or go through in other for me to achieve my desired paper size. I Am currently using dompdf to print out receipt for customer in my Laravel project. But the current paper size is A4. I would like to get the paper to be half of A4 size. How can I adjust this from my code.?

->setPaper('A4', 'landscape');

Thanks for your assistance.

0 likes
8 replies
wing5wong's avatar

Half of A4 landscape size is A5 portrait

2 likes
delyn12's avatar

Good evening. I did tryA5 landscape but the printing doesn't print nice on the paper. The preview was accurate on system but the printing was sideways instead of landscape.

delyn12's avatar

Here is my code From pDFSupport Helper file I have this

public function get_paper_size()
    {
        switch (paperSize())
        {
            case 'A4_half' :
                $size = 'A5';
                $mode = 'landscape';
                break;
            case 'A4' :
                $size = "A4"; //0, 0, 595.28, 841.89
            $mode = "portrait";
                break;
        }
        return (['size' => $size, 'mode' => $mode]);
    }

from Invoice Support

    public function get_invoice_pdf($data){
        $invoice = $data;
        $title = $this->PDFSupport->page_title();
        $path = "Template_".TEMPLATE().'.'.paperSize();

            $pdf = PDF::loadView('pdf::'.$path.'.Invoices.'.$this->PDFSupport->title(), compact('invoice', 'title'))
           // ->setPaper($this->PDFSupport->get_paper_size(), 'portrait');
                ->setPaper( $this->PDFSupport->get_paper_size()['size'],  $this->PDFSupport->get_paper_size()['mode']);
        return $pdf;
   }

The issue now is that whenever I made attempt to print the A5 landscape. It will rotate 180 deg on screen and print same way on the paper instead of printing same landscape mode to fit the half of A4 paper.

mike_isp's avatar

What if you keep $mode as 'portrait' when using A4_half?

forsxs's avatar

My solution: Use css style in blade

        @page {
            size: A4 landscape;
            margin: 10px;
        }

and separate page in 2 block with 45% width each

Please or to participate in this conversation.