nizam0786's avatar

A4 page generator with fixed header and footer from HTML

Hi Guys,

I was wondering if there is a package or a way of automatically generating/splitting a html page into a4 pages so i can easily print it out. I have tried printing it out as is but the body i.e. contents overlaps the footer and header which I can't really find a way to fix.

Thanks in advance.

0 likes
5 replies
FrankClark's avatar
Level 2

@nizam0786 - My advice would be to generate a PDF of a view. I have used this package in the past and have no complaints : https://github.com/barryvdh/laravel-dompdf

...
use PDF;
...
    public function downloadPdf(MyThing $myThing)
    {
        $data = $myThing->toArray()

        // Return as a HTML page for debugging
        // return view("simple-blade-template-with-header-and-footer", $data);

        $pdf = PDF::loadView("simple-blade-template-with-header-and-footer", $data);

        // Output PDF to view rather than downloading for debugging
        // return $pdf->stream();

        // Actually trigger a download
        return $pdf->download("my-pdf.pdf");
    }

If you want something more simple you can actually just use the @media print css media query. You can then get rid of some stuff in the view that's messing with the layout.

for example:

@media print
{    
    .print-hidden
    {
        display: none !important;
    }
}
1 like
nizam0786's avatar

Hi @frankclark I looked into many options but in the end I used the package which you mentioned. I had it already installed and was wondering if there was anything else. I guess I will have to do with it :)

Thank you anyway for your help.

vlcya's avatar

Is there any way to use this with bootstrap 4?

Please or to participate in this conversation.