2017-09-15 12 views
1

私はflyingsaucer 9.1.1とitext 2.17を使ってPDFファイルを生成しています。最後のページにのみフッタを表示

最後のページのみでフッター(div、表、またはimg要素)を表示するにはどうすればよいですか?

+1

iTextの2.1.7は、私がかつて書いたAPIであり、(https://developers.itextpdf.com/question/versions-older-than-5)[それはもはや使用すべきではありません]。あなたがもはやそれを使うべきではない理由の一つは、時代です。 iText 2.1.7の日付は2009年です。また、Flying Saucerも使用しています。これは古いiTextバージョンの上に書かれた古いサードパーティのライブラリです。 [iText 7 + pdfHTML](https://developers.itextpdf.com/content/itext-7-converting-html-pdf-pdfhtml)の使用を検討する必要があります。このチュートリアルを閲覧すると、[pdfHTML](https://itextpdf.com/itext7/pdfHTML)にCSSのサポートがはるかにあることがわかります。 –

+1

あなたの質問については、IEventHandlerを使ってカスタム動作を示すフッターを作成することができます。正しいことをしてiText 7にアップグレードすることを決めるべきです。[チュートリアル](https://developers.itextpdf.com/content/itext-7-html-pdf-pdfhtml/chapter-4-creating-reports-using-pdfhtml)には、カスタムヘッダーやフッターの作成方法の例があります。 [このコメント](https://stackoverflow.com/questions/46238645/utf-8-encoding-characters-not-working-with-spring-mvc-lowagie-itext#comment79441200_46238645)もお読みください。 –

答えて

3

残念ながら、CSSはpage:first疑似要素を定義しますが、page:lastは定義しません。

フライングソファのbugを利用する可能性があります。これにより、フッターが宣言された後にのみ表示されます。したがって、フッタdivをHTMLの最後に置くと、最後のページにのみ表示されます。

<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);}  
} 
</style> 
</head> 
    <body> 
     <div>Page 1 content</div> 
     <div class="newpage">Page 2 content</div> 
     <div class="newpage">Page 3 content</div> 
     <div id="footer">Footer on last page</div> 
    </body> 
</html> 

各ページのフッターをしたい場合にも、最後のページのためのさまざまなコンテンツで、動作します。フッタdivをHTMLで2回定義するだけです。

<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);}  
    } 
</style> 
</head> 
    <body> 
     <div id="footer">Footer for all pages except last</div> 
     <div>Page 1 content</div> 
     <div class="newpage">Page 2 content</div> 
     <div class="newpage">Page 3 content</div> 
     <div id="footer">Footer on last page</div> 
    </body> 
</html> 
関連する問題