Freemarker,PDF,页眉/页脚和分页符 [英] Freemarker, PDF, Header/Footer and page-breaks
问题描述
不幸的是,我必须生成一个包含大量页面的pdf,并且他们要求我把一个带有一些信息的页眉,以及一些页面,比如page 2/60等等。
在网上搜索我发现了如何创建一个宏模板,但它只是共享一些常见的标签(如css),但它并没有告诉freemarker如何管理多页PDF。除此之外,有时我在ftl里面有一个页面中断css类,所以我不能确定何时何地创建新页面。
我在Java上使用Freemakrer 2.3
感谢您的帮助。
您可以使用CSS指定页眉和页脚(包括页码) 。
如果用于将XHTML转换为PDF字节数组的工具支持分页的媒体指令,则这将起作用。
在CSS中:
@page {
@ top-center {content:element(header)} / * Header * /
@ bottom- {position:running(header);}
#footer {position:running(footer);} $ {center:{content:element(footer)} / * Enpied * /
}
#header {position: b $ b #pagenumber:before {content:counter(page);}
#pagecount:before {content:counter(pages);}
在HTML中:
< div id =header>您的头文件< / div>
< div id =footer>页面< span id =pagenumber/> /< span id =pagecount/>< / div>
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.
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>
这篇关于Freemarker,PDF,页眉/页脚和分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!