本文主要是介绍oracle.xdo.template.FOProcessor根据xml、xsl(rtf)动态生成pdf,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.制作模板
使用Oracle_BI_Publisher
Oracle_BI_Publisher中文开发教程(创建RTF模板)
2.用xml,xsl(rtf)动态生成pdf
api文档:
FOProcessor (Oracle Fusion Middleware Java API Reference for Oracle Business Intelligence Publisher)
3.分析模板使用office插件,用32位,64位用不了:
Oracle Analytics Publisher - Downloads | Oracle Technology Network | Oracle
打开rtf模板
4.根据rtf模板构建xml
Node root = Node.getDefault();
root.addNode("_XDONFSEPARATORS",".");
root.addNode("COMPANY_NAME","公司名称");
root.addNode("ASN_HEADER_QR_CODE","公司名称");
root.addNode("ASN_NUM","公司名称");
root.addNode("SUPPLIER_NAME","公司名称");
root.addNode("SHIP_DATE","公司名称");
root.addNode("ORGANIZATION_NAME","公司名称");
root.addNode("PURCHASECONTACTOR","公司名称");
root.addNode("EXPECTED_ARRIVE_DATE","公司名称");
root.addNode("SHIP_TO_LOCATION_ADDRESS","公司名称");
root.addNode("ATTRIBUTE_VARCHAR37","公司名称");
Node asnLines = root.addNodeGroup("asnLines");
asnLines.addNode("ASN_LINE_NUM","行数据");
asnLines.addNode("DISPLAY_PO_NUM","行数据");
asnLines.addNode("DISPLAY_LINE_NUM","行数据");
asnLines.addNode("ITEM_CODE","行数据");
asnLines.addNode("ITEM_NAME","行数据");
asnLines.addNode("SHIP_QUANTITY","行数据");
asnLines.addNode("UOM_NAME","行数据");
asnLines.addNode("LOT_NUM","行数据");
asnLines.addNode("PACKAGE_QUANTITY","行数据");
asnLines.addNode("PRODUCTION_DATE","行数据");
asnLines.addNode("TANKNUMBER","行数据");
asnLines.addNode("QUANTITYTYPE","行数据");
asnLines.addNode("REMARK","行数据");
Node asnLines2 = root.addNodeGroup("asnLines");
asnLines2.addNode("ASN_LINE_NUM","行数据2");
asnLines2.addNode("DISPLAY_PO_NUM","行数据2");
asnLines2.addNode("DISPLAY_LINE_NUM","行数据");
asnLines2.addNode("ITEM_CODE","行数据");
asnLines2.addNode("ITEM_NAME","行数据");
asnLines2.addNode("SHIP_QUANTITY","行数据");
asnLines2.addNode("UOM_NAME","行数据");
asnLines2.addNode("LOT_NUM","行数据");
asnLines2.addNode("PACKAGE_QUANTITY","行数据");
asnLines2.addNode("PRODUCTION_DATE","行数据");
asnLines2.addNode("TANKNUMBER","行数据");
asnLines2.addNode("QUANTITYTYPE","行数据");
asnLines2.addNode("REMARK","行数据");
System.out.println(root.asXML());
//本地测试 public void localTest(Node node){InputStream xslByteArrayInputStream = null;try {//本地测试用到,后期删除ByteArrayOutputStream xslByteArrayOutputStream = new ByteArrayOutputStream();RTFProcessor rtfProc = new RTFProcessor("D://test.rtf");rtfProc.setOutput(xslByteArrayOutputStream);rtfProc.process();xslByteArrayInputStream = new ByteArrayInputStream(xslByteArrayOutputStream.toByteArray());InputStream xmlInputStream = generateXML(node.asXML());FOProcessor processor = new FOProcessor();processor.setData(xmlInputStream);processor.setTemplate(xslByteArrayInputStream);processor.setOutputFormat(FOProcessor.FORMAT_PDF);processor.setOutput("D://test.pdf");processor.setLocale(Locale.CHINA);processor.setConfig(getProperties());processor.generate();} catch (Exception e) {throw new CommonException(e.getMessage());} }/*** 自定义配置* 本地测试* @return*/ public Properties getProperties() {Properties prop = new Properties();setFontProperties(prop);return prop; }//设置pdf可以支持的字体,本地测试 public void setFontProperties(Properties prop) {String resourcePath = PdfUtil.class.getClassLoader().getResource("fonts").getPath();prop.put("font.黑体.normal.normal", "truetype." +resourcePath + "/simhei.ttf");prop.put("font.仿宋.normal.normal", "truetype." +resourcePath + "/simfang.ttf");prop.put("font.楷体.normal.normal", "truetype." +resourcePath + "/simkai.ttf");prop.put("font.宋体.normal.normal", "truetype." +resourcePath + "/simsun.ttc"); }
5.本地调试可能导出都是?乱码,原因:字体文件没找到
prop.put("font.黑体.normal.normal", "truetype.D://simhei.ttf");
这篇关于oracle.xdo.template.FOProcessor根据xml、xsl(rtf)动态生成pdf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!