How to generate two pages with DOMPDF in Laravel

Asked

Viewed 121 times

0

I have to generate the PDF of a 'wallet', and I have to put the front and back in the same file. I have the following source to generate the front:

$nome = $cliente->nome.'.pdf';
$pdf = \PDF::loadView('cliente.print', array('cliente' => $cliente));
$customPaper = array(0,0,153.00,240.90);// tamanho personalizado
return $pdf->setPaper($customPaper, 'landscape')->stream($nome);

The generation comes out perfect as in the photo below, now I want to add a second page just below and put the image on the back.

I already searched and tried to pass the second page in the custom size array but could not solve.

inserir a descrição da imagem aqui

  • Have you ever tried to generate this wallet with HTML and CSS? Each card could be a div and you can use a <br> to break them. I think it would be a good solution.

  • Yes the first page I did totally with HTML and CSS, because the data came dynamically from the database. However the second page is an image.

  • 1

    The solution to your question you find here: https://stackoverflow.com/questions/22746958/dompdf-adding-a-new-page-to-pdf/43911627#43911627 But I believe it is the case to add a new <div> and continue styling.

  • 1

    Have you thought about page-break-after?

  • Yes it was solved using page-break. Thank you.

1 answer

1


Based on users' Soen responses cotton and Brians:

DOMPDF handles paging automatically. If you want to force a page break you can use the CSS style page-break-before: always; or page-break-after: always;

From this form you can include an element to break the page:

CSS

.page-break { page-break-before: always; }

HTML

<div class="page-break"></div>

Or add the style to an existing element.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.