本例可将xml格式数据按xsl模板转化为PDF
1.首先,程序结构如下:
2.FopReport.java
1.首先,程序结构如下:
2.FopReport.java
- // Step 1: Construct a FopFactory
- private static final FopFactory fopFactory = FopFactory.newInstance();
- /**
- * 根据xsl模板及xml数据文件生成pdf
- * @param xsltFile xsl模板
- * @param xmlFile xml数据文件
- * @return ReportData
- * @throws Exception
- * @author bin.yin 2012/12/25
- */
- public static ReportData createReport(String xsltFile, String xmlFile) throws Exception {
- ReportData reportData = new ReportData();
- reportData.setContentType("application/pdf");
- fopFactory.setUserConfig("conf/fop.xml");
- // Step 2: Set up output stream.
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- try {