DOMPDF page orientation both landscape and portrait

In HTML formed sheet 3 . Each sheet is a table . We need something to convert to pdf with the last leaf was in a landscape ! With portraits it works, and how to make one of the sheets of the album .... I do not understand ...

Upvotes: 10

Views: 50873

Answers (2)

MUHINDO
MUHINDO

Reputation: 1241

Simply write this simple CSS in your doc and you will be good to go!

<style>
    @page {
        size: A4 landscape;
    }
</style>

HOPE IT HELPS!

Upvotes: 2

BrianS
BrianS

Reputation: 13924

dompdf is currently unable to do this. If you want to continue using dompdf you'll have to generate the different orientated sections separately and then combine them using an external application.

There are a number of apps for combining mutiple PDF documents. In the past I've used pdftk. It's an executable, so you would need to be able to install/run it on your system. For example:

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->load_html('...');
$dompdf->render();
file_put_contents($dompdf->output(), 'pdf1.pdf');
unset($dompdf);

$dompdf = new DOMPDF();
$dompdf->set_paper('letter', 'landscape');
$dompdf->load_html('...');
$dompdf->render();
file_put_contents($dompdf->output(), 'pdf2.pdf');

exec('pdftk A=pdf1.pdf B=pdf2.pdf cat A1 B2 output combined.pdf');

I haven't used it, but libmergepdf looks like a decent solution.

use iio\libmergepdf\Merger;
use Dompdf\Dompdf;

$m = new Merger();

$dompdf = new Dompdf();
$dompdf->load_html('...');
$dompdf->render();
$m->addRaw($dompdf->output());
unset($dompdf);

$dompdf = new DOMPDF();
$dompdf->set_paper('letter', 'landscape');
$dompdf->load_html('...');
$m->addRaw($dompdf->output());
$dompdf->render();

file_put_contents('combined.pdf', $m->merge());

Upvotes: 14

Related Questions