Flying Saucer很强大支持CSS样式,可以直接将html转换成PDF,而且免费跨平台。
下面我来说一下生成PDF页码
开始我以为生成页码会和Itext一样在程序中实现,但是不遂人愿,程序实现是不对的。后来我查了英文说明网站(因为英语不咋的实在懒得看)
http://today.java.net/pub/a/today/2007/06/26/generating-pdfs-with-flying-saucer-and-itext.html#page-specific-features
找到了显示页码的方法是在CSS操作
@page {
size: 4.18in 6.88in;
margin: 0.25in;
-fs-flow-top: "header";
-fs-flow-bottom: "footer";
-fs-flow-left: "left";
-fs-flow-right: "right";
border: thin solid black;
padding: 1em;
}
#header {
font: bold serif;
position: absolute; top: 0; left: 0;
-fs-move-to-flow: "header";
}
#footer {
font-size: 90%; font-style: italic;
position: absolute; top: 0; left: 0;
-fs-move-to-flow: "footer";
}
#pagenumber:before {
content: counter(page);
}
#pagecount:before {
content: counter(pages);
}
还有一段HTML里面代码
<div id="header" style="">Alice's Adventures in Wonderland</div>
<div id="footer" style=""> Page <span id="pagenumber"/> of <span id="pagecount"/> </div>
这样就可以显示了,但是仅能显示一页,把“Page <span id="pagenumber"/> of <span id="pagecount"/>”放到第二页时就显示第二页,没办法不给力啊,页数不能控制。
峰回路转我有找到另一个CSS样式
@page {
size: 4.18in 6.88in;
margin: 0.25in;
border: thin solid black;
padding: 1em;
@bottom-center{
content:"@xxoo有限公司 版权所有";
font-family: SimSun;
font-size: 9px;
color:red;
};
@top-center { content: element(header) };
@bottom-right{
content:"page " counter(page) " of " counter(pages);
font-family: SimSun;
font-size: 9px;
color:red;
};
}
div#myheader {
display: block;
position: running(header);
}
其实第一种方案是过时的写法,第二种才是现在的写法。
转自
http://topic.csdn.net/u/20111012/11/0e65faba-de91-4104-9aa1-eb7cd9c97ce2.html
我稍微改了一下
@page {
margin: 0.25in;
padding: 1em;
@bottom-center{
content:"@OOXX 版权所有";
font-family: SimSun;
font-size: 9px;
color:red;
};
@top-center { content: element(header) };
@bottom-right{
content:"第" counter(page) "页 共 " counter(pages) "页";
font-family: SimSun;
font-size: 9px;
color:#000;
};
}
div#myheader {
display: block;
position: running(header);
}
#pagenumber:before {
content: counter(page);
}
#pagecount:before {
content: counter(pages);
}
生成的例子
- 大小: 5.7 KB
- 大小: 5.9 KB
分享到:
相关推荐
flying-saucer生成pdf解决大部分的问题 1.图片显示问题 2.中文显示问题,css样式问题 3.表格跨行问题
Flying Saucer生成pdf文档jar包 ,已做修改,支持中文 换行,但是 table标签换行 请改用CSS 样式:style="table-layout:fixed; word-break:break-strict;
flying-saucer-pdf 生成pdf解决图片问题 解决中文问题
实例介绍,包含中文问题的解决方法等,在生成pdf的过程中遇到的问题。希望对大家又算帮助
3. 运行Junit测试类 TestPdfGenerator.testGenerate()即可生成,pdf生成路径见日志. 4. 如果没有maven环境,需要手动下载以下依赖包: commons-pool-1.5.1.jar flying-saucer-core-9.0.3.jar flying-saucer-pdf-...
iText+Flying Saucer生成pdf文档jar包(修改后的)支持中文
使用flyingsaucer将网页转换为pdf之中文问题彻底解决
SpringBoot集成Freemarker+FlyingSaucer实现pdf在线预览.pdf
基于iText 和 flying saucer结合freemark java 生成 pdf
flying-saucer-pdf-9.0.9.jar; flying-saucer-core-9.0.9.jar; freemarker.jar; itext-2.1.7.jar;
iText+Flying Saucer生成pdf文档,中文不显示和不自动换行问题重新Breaker.class
flying-saucer-pdf-itext5-9.0.3.jar
flying sauser,基于iText自身的问题,让我们开始寻求可以真正意义上模版技术,那么flying sauser就是为了这个问题出现的产品,能解析HTML和CSS,而且能输出成image,PDF等格式。具体使用,请访问:...
本资源是自己在利用itext和flying saucer将html生成pdf,并使用freemarker模板引擎的样例
flying-saucer-coreR-9.0.7 中修改Breaker类,解决PDF中文没有对齐问题。
官方指导手册,教你如何使用
flying-saucer 导出pdf的jar包下载,包含core-renderer、flying-saucer-pdf、flying-saucer-core、itext-2.1.7等jar包
NULL 博文链接:https://songlixiao.iteye.com/blog/706417
转pdf需要的jar包,亲测好用转pdf需要的jar包,亲测好用
Flying Saucer 支持中文宋体win,Linux; Css 页面字体修改为 font-family:STSong; 就可以了,具体