Snappy footer generate a weird margin proportional to its size

1.7k views Asked by At

first, let me show you the piece of code that makes the bug happen.

Here is the code of my footer :

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">

</head>
<body>
<div style="height: 1rem; background-color: #1C440C">

    <span>Hello world</span>

</div>
</body>
</html>

The main page :

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">

</head>
<body>


    Hello world page

</body>
</html>

And the controller :

   /**
     * @Route("/path", name="myurl")
     */
    public function toPdf()
    {
        $html = $this->renderView('pdf/page.html.twig');
        $footer = $this->renderView('pdf/footer2_pdf.html.twig');
        return new Response(
            $this->get('knp_snappy.pdf')->getOutputFromHtml($html, array(
                'footer-html' => $footer
            )),
            200,
            array(
                'Content-Type'          => 'application/pdf',
                'Content-Disposition'   => 'attachment; filename="file.pdf"'
            )
        );

Il I set the footer height to 1 (like it is in the code sample), I get this kind of pdf footer :

enter image description here

the distance between the "hello world" and the bot of the page looks like the default margin of the pdf, so it looks like it is ok.

Then, if I change the height to 5rem to get a larger footer, I get this :

enter image description here

The footer is larger, but the margin between the footer and the end of the page just increased like crazy. I don't really understand why.

Thank you for reading, if you know the answer, feel free to answer.

1

There are 1 answers

0
Daneel On BEST ANSWER

For future reference, just set the bottom margin with this solution : pdf page margins with snappy and symfony2 Cheers !