The footer is on the last page, while the assembly of the PDF using the flying saucer

I am using the flaying saucer jay library.

I am trying to add footers to the generated pdf file.

The goal is to have the same footer on each page and different content on the last page.

html>
<head>
    <style type="text/css">

    @page {
            size: 8.5in 11in;
            margin-bottom: 1in;

            @bottom-left {
                content: element(footer_one);
            }

            @bottom-right{
                content: element(footer_two);
            }
            @bottom-center{
                content: element(footer_rights);
        }
    }

    #footer_two {position: running(footer_two); }
    #footer_one {position: running(footer_one); }
    #footer_three {position: running(footer_three);}

    #footer_two, #footer_one, #footer_three { margin: 0 padding:0;}
    #footer_three { border-top: 2px solid #3390FF;}
    </style>
</head>
<body>
    <div id="footer_one">
        some text short text about three words, on each page
    </div>
    <div id="footer_two">
        some text short text, like page numbers etc, on each page
    </div>

   <div>
      Whole body content 
    </div>

    <div id="footer_three">
        some text looooooooonnnnnnnnnggggggggg text, some about ten rows. Only on last page
    </div>
</body>

I have been struggling with this for about a few days, and any advice found on the net was not good enough.

I tried with

@page:last {} 

or using:

@bottom-left {
                content: element(footer_one, last-except);
            }

            @bottom-right{
                content: element(footer_two, last-except);
            }

but it seems that: the last pseudo selector is not working.

The best approach would be to have a completely different one footer on the last page, which would include the contents of these three footers. I can only add a footer on the last page, but I cannot disable these simple footers from previous pages.

, ? .

+4
2

:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>last footer</title>

    <style type="text/css">
        div.pdf-footer {
            padding-top: 4pt;
            position: running(footer);
        }

        @page {
            @bottom-center {
                content: element(footer, last);
            }
        }
    </style>
</head>
<body>
    <div class="pdf-footer">all pages except last</div>

    <div>content</div>

    <div class="pdf-footer">only last page</div>
</body>
</html>
+4

, , CSS3 .

:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <style type="text/css">
    .newpage{page-break-before:always}

    @page {@bottom-center {content: element(footer)}}
    #footer {position: running(footer);}

    @page last {@bottom-center {content: element(lastfooter)}}
    #lastfooter{position: running(lastfooter);}
    #lastpage  {page:last}
}
 </style>
</head>
    <body>  
        <div id="footer">Footer for all pages except last one</div>
        <div id="lastfooter">Footer for last page</div>

        <div>Content for all pages except last one</div>
        <div class="newpage" id="lastpage">Last page content</div>
    </body>
</html>
+1

Source: https://habr.com/ru/post/1529794/


All Articles