Often, many web application required functions like export to pdf, but not all the time is A4 paper size.

I'm using laravel-dompdf for the project. I will not talk about the setup. Let's see the code directly.

PdfController.php

1
2
3
4
5
6
<?php
$file = 'download-file-name.pdf';
$pdf = \PDF::loadView('download.pdf', ['data' => $some_data])
->setPaper('a4', 'landscape');
return $pdf->download($file);

The code above, will generate & download the pdf file in A4 paper size. But what if different paper size is needed?

You can set the paper size to any size you want

1
$pdf->setPaper([0, 0, 685.98, 396.85], 'landscape');

(Bare in mind that the value is in point unit)

You can measure the paper with your ruler.

Measure paper size

But what you measure is in centimeter (cm) or millimeter (mm), so you can ask google to convert the unit for you

Google converter

Done.

References: