Нижний колонтитул на последней странице при генерации PDF на летающей тарелке

Я использую Java-библиотеку с блюдцем.

Я пытаюсь добавить нижние колонтитулы в мой сгенерированный PDF.

Цель состоит в том, чтобы на каждой странице был один и тот же нижний колонтитул и разный контент на последней странице.

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>

Я борюсь с этим около нескольких дней, и любой совет, найденный в сети, был недостаточно хорош.

Я пытался с

@page:last {} 

или с:

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

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

но кажется, что: последний псевдо-селектор не работает.

Наилучшим подходом будет иметь совершенно другой нижний колонтитул на последней странице, который будет включать содержимое этих трех нижних колонтитулов. Я могу добавить нижний колонтитул только на последней странице, но не могу отключить эти простые нижние колонтитулы с предыдущих страниц.

Может быть, есть какой-то другой подход? Буду признателен за любую помощь.

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>

Если вы заранее знаете, что будет отображаться на последней странице, вы можете использовать именованные страницы 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>
Другие вопросы по тегам