栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

FopFactory.newInstance()时出现Fop异常

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

FopFactory.newInstance()时出现Fop异常

我解决了我的问题!我有xmlgraphics-commons-1.3而不是xmlgraphics-commons-1.5。这很奇怪,因为我使用了fop
bin附带的所有库。

顺便说一下,转换并在浏览器中显示pdf文件的代码如下:

<action name="printDomAction"   method="xmlToPdf">        <result type="stream" name="success"> <param name="contentType">application/pdf</param> <param name="contentDisposition">filename="ResultXML2PDF.pdf"</param> <param name="bufferSize">1024</param>        </result>        <interceptor-ref name="defaultStack"/>    </action>

和方法

private InputStream inputStream;public String xmlToPdf() {     try {         System.out.println("FOP ExampleXML2PDFn");         System.out.println("Preparing...");         // Setup directories         File baseDir = new File("C:\Users\Administrator\workspace\path\actions\forms\");         File outDir = new File(baseDir, "out");         outDir.mkdirs();         // Setup input and output files         File xmlfile = new File(baseDir, "testeFOPxml.xml");         File xsltfile = new File(baseDir, "xml2fo.xsl");         File pdffile = new File(outDir, "ResultXML2PDF.pdf");         System.out.println("Input: XML (" + xmlfile + ")");         System.out.println("Stylesheet: " + xsltfile);         System.out.println("Output: PDF (" + pdffile + ")");         System.out.println();         System.out.println("Transforming...");         // configure fopFactory as desired         final FopFactory fopFactory = FopFactory.newInstance();         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();         // configure foUserAgent as desired         ByteArrayOutputStream out = new ByteArrayOutputStream();         TransformerFactory tFactory = TransformerFactory.newInstance();         Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent, out);         //Setup input         Source src = new StreamSource(xmlfile);         //Setup Transformer         Source xsltSrc = new StreamSource(xsltfile);         Transformer transformer = tFactory.newTransformer(xsltSrc);         //Make sure the XSL transformation's result is piped through to FOP         Result res = new SAXResult(fop.getDefaultHandler());         transformer.transform(src, res);         System.out.println("Success!");         ByteArrayOutputStream baos = out;         inputStream = new ByteArrayInputStream(baos.toByteArray());     } catch (Exception e) {     e.printStackTrace(System.err);         System.exit(-1);     } return SUCCESS; }

感谢大家的提示和帮助!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515605.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号