1.导入pom依赖
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.3</version>
</dependency>
2.查看官方案例
当前的方式为(来自官方的demo):使用的方式
所以需要创建pdf文件需要两个东西:
1.xml配置文件用于存储所需要的数据
2.xsl文件用来作为动态解析的对象
3.什么是XSL?
个人查看:w3school中的内容
所以可以使用xsl:for-each来迭代数据,使用xsl:value-of来绑定数据
3.如何在当前的xsl中使用表格和其他样式
本人使用菜鸟教程中的fo
所以可以使用fo标签来制作表格
4.开始编写helloworld.xml以及helloworld.xsl文件
helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<title>当前所有的用户列表</title>
<user>
<name>admin</name>
<age>18</age>
<onwork>true</onwork>
<isleaf>yes</isleaf>
</user>
<user>
<name>guest</name>
<age>20</age>
<onwork>false</onwork>
<isleaf>no</isleaf>
</user>
</users>
helloworld.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output