Flying Saucer生成pdf报表

使用Flying Saucer生成pdf报表:


1.首先看一下Flying Saucer的官方介绍:

https://github.com/flyingsaucerproject/flyingsaucer

OVERVIEW

Flying Saucer is a pure-Java library for rendering arbitrary well-formed XML (or XHTML) using CSS 2.1 for layout and formatting, output to Swing panels, PDF, and images.

Comprehensive documentation available in our user's guide, linked from our website at http://code.google.com/p/flying-saucer/ For information on our development releases, please contact us on our mailing lists.

If you end up using Flying Saucer for your own projects, please drop us an email and tell us about it; it helps inform where we go next, and is interesting and inspiring to other developers.

可以看到Flying Saucer可以完美的解析html,并且可以使用css2.1的样式,添加图片等功能。


2.简单的使用:

业务上经常有这样的场景:

将用户信息查询出来并且显示在页面上设计好的table上。并且可以选择下载。

解决方法:

1.)使用java模板(velocity、freemarker等)定义好表格样式,这里我们使用freemarker

引入freemarker

<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.23</version>
</dependency>

创建ftl模板

<!DOCTYPE html>
<html>
	<head>
		<style type="text/css">
			.tg {
				border-collapse: collapse;
				border-spacing: 0;
			}
			
			.tg td {
				font-family: 'Arial Unicode MS';
				font-size: 14px;
				padding: 16px 5px;
				border-style: solid;
				border-width: 1px;
				overflow: hidden;
				word-br/eak: normal;
			}
			
			.tg th {
				font-family:'Arial Unicode MS';
				font-size: 14px;
				font-weight: normal;
				padding: 16px 5px;
				border-style: solid;
				border-width: 1px;
				overflow: hidden;
				word-break: normal;
			}
			
			.tg .tg-s6z2 {
				text-align: center
			}
			
			.tg .tg-baqh {
				text-align: center;
				vertical-align: top
			}
			
			.tg .tg-yw4l {
				vertical-al
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值