I have used this code to make a Custom PDF to make purchase orders also with some custom attributes but the base code is the same: https://webkul.com/blog/generate-pdf-programmatically-magento2/ This works great, however when the amount of products is for example >10 and it doesn't fit on the page anymore, instead of making a new page and continuing it prints it all on 1 page and it goes off screen, the data is there when u select all text on PDF just not visible. How can i use this code to create a page break when the amount of products doesn't fit on page anymore?

1 Answer 1


You can simply use or copy the core method \Magento\Sales\Model\Order\Pdf\Invoice::newPage that add a new blank page to your pdf.

I also just wrote a custom class to render invoice as PDF on magento 2, and as I loop through all invoice items, I check if the Y position is high enough (page bottom is 0), else I add a new page and set the Y position to the top of that page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.