Festo Festo - 3 months ago 84
CSS Question

How to separate body content with fixed header and footer for multiple pages

I Have three separate section as

header
,
body
and
footer
to create pdf.

Header part will come always at top of each page and it will be fix.

______________________
| header |
|______________________|


Problem is with body content, if content is big it will go to second page.

______________________
| |
| |
| body |
| |
| |
|______________________|


Footer part will come always at bottom of each page and it will also fix.

______________________
| footer |
|______________________|


So If content is big and if two pages created then I should get two pages as:

______________________
| header |
|______________________|
| |
| |
| Body Part1 |
| |
| |
|______________________|
| footer |
|______________________|


And

______________________
| header |
|______________________|
| |
| |
| Body part2 |
| |
| |
|______________________|
| footer |
|______________________|


I tried with table format, It is working for header and content, but not worked for footer. Footer is coming only in bottom of second page not in first page.

I am using laravel dompdf

Any help would appreciated.

Answer

I checked this helpful answer : http://stackoverflow.com/a/1763683/5830872 again and with some changes and external div tag Its working for me.

I don't Know how laravel dompdf converts this html to pdf but it works for me.

Here is my laravel code

Route::get('/', function () {
    $output = '<style>';
    $output .= '
        .divFooter {position: fixed;bottom: 20;text-align:center;}
                ';
    $output .= '</style>';
    $output .= '<div class="divFooter" style="color:red;"><h1>This is footer</h1></div>';
    $output .= '<table width="100%"><thead><tr><th><div style="color:red;"><h1>This is header</h1></div><th></tr></thead>';
    $output .= '<tbody><tr><td>';
    $output .= 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</td></tr>
      .........................
      .........................
      .........................
    ';
    $output .= '</tbody></table>';
    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML($output);
    return $pdf->stream();
});

Which generating pdf like this : http://content.screencast.com/users/Niklesh2/folders/Jing/media/13bb7a6f-f280-46db-94df-1af6270b4b02/2016-08-10_1713.png

I am sorry I am not able to tell you how its working. But may be helpful for others who is working in laravel dompdf.

cheers !!

Comments