Using DomPDF in Laravel and other PHP projects

Before Converting HTML to PDF

Ensure that the page has been set to the correct dimensions in the controller. When loading the PDF View you can set the paper. Something along the lines of:

$pdf = PDF::loadView('folder-name.file-name')->setPaper('a4', 'portrait');

Also note that the container div of each page should be set to the same dimensions as the paper, you can set the width and height in mm to do this.

Tips when creating a PDF

Since you cannot use tools like inspect element when viewing a PDF you are limited in how you can test and debug.

It is good to switch between HTML and PDF view (if possible) but if you can't do this, please note the following: