Freemarker, PDF, Header/Footer and page-breaks

坚强是说给别人听的谎言 提交于 2019-12-06 04:14:50

问题


A common use of Freemarker is the generation of a PDF.

Unfortunally I have to generate a pdf with a lot of pages and "they" asking me to put an header with some information and a footer with somethings like "page 2/60" etc...

Searching on web I found how to create a Macro template but it only share some common tags (like css) but it doesn't tell freemarker how to manage multipage PDF.

In addition to this, sometimes I have, inside ftl, a "page-break css class" so I cant determine when and where a new page is created.

Im using Freemakrer 2.3 on Java

Thanks for any help.


回答1:


You can specify a header and a footer (including page numbers) with CSS. This will work if the tool used to transform your XHTML into the PDF byte array supports the paged media instructions.

In the CSS:

@page { 
    @top-center {content: element(header)}      /* Header */
    @bottom-center {content: element(footer)}   /* Enpied */
}
#header {position: running(header);}
#footer {position: running(footer);}
#pagenumber:before {content: counter(page);}
#pagecount:before {content: counter(pages);}

In the HTML:

<div id="header">YOUR HEADER HERE</div>
<div id="footer">Page <span id="pagenumber" /> / <span id="pagecount" /></div>


来源:https://stackoverflow.com/questions/16670704/freemarker-pdf-header-footer-and-page-breaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!