DOMPDF page orientation both landscape and portrait

Влад Паздников picture Влад Паздников · Mar 15, 2016 · Viewed 24.5k times · Source

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 ...

Answer

BrianS picture BrianS · Mar 15, 2016

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());