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

moses's avatar
Level 2

How to setting landscape in laravel-dompdf?

I get reference from here : https://github.com/barryvdh/laravel-dompdf

My controller code is like this :

public function listdata()
{
    $pdf=PDF::loadView('pdf.test_pdf');
    return $pdf->stream('test_pdf.pdf');
}

I try setting landscape in \config\dompdf like this :

'show_warnings' => false,   // Throw an Exception on warnings from dompdf
'orientation' => 'landscape',

But, it's not working. The result is still portrait

Is there any people who can help me?

0 likes
2 replies
willvincent's avatar
Level 54

It doesn't look like the constructor ever actually populates the orientation value.

Try this:

public function listdata()
{
    $pdf = PDF::loadView('pdf.test_pdf');
    $pdf->setPaper('A4', 'landscape');
    return $pdf->stream('test_pdf.pdf');
}

Probably the constructor should be updated from:

public function __construct(Dompdf $dompdf, ConfigRepository $config, Filesystem $files, ViewFactory $view){
        $this->dompdf = $dompdf;
        $this->config = $config;
        $this->files = $files;
        $this->view = $view;

        $this->showWarnings = $this->config->get('dompdf.show_warnings', false);
    }

to:

public function __construct(Dompdf $dompdf, ConfigRepository $config, Filesystem $files, ViewFactory $view){
        $this->dompdf = $dompdf;
        $this->config = $config;
        $this->files = $files;
        $this->view = $view;

        $this->showWarnings = $this->config->get('dompdf.show_warnings', false);
        $this->orientation = $this->config->get('dompdf.orientation', 'portrait');
    }

That should probably be submit as a PR if that resolves the issue.

and/or any reference to $this->orientation in the PDF class should be updated to use the config value.

2 likes
moses's avatar
Level 2

@willvincent, Thank you. It's working. I just edit to be like this :

public function listdata() { $pdf = PDF::loadView('pdf.test_pdf'); $pdf->setPaper('A4', 'landscape'); return $pdf->stream('test_pdf.pdf'); }

I don't edit custructor. Because, without edit custructor, it's working

Please or to participate in this conversation.