问题
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