700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > java处理word公式(wmf格式转换成svg)

java处理word公式(wmf格式转换成svg)

时间:2024-07-19 23:59:13

相关推荐

java处理word公式(wmf格式转换成svg)

做word文档在线预览,把word转化成html后,里面的公式的格式为.wmf格式,在浏览器中不能显示,故我把wmf格式转化成svg格式,这样就能在浏览器中显示了

需要第三方jar包:wmf2svg-0.9.6.jar

//wmf格式的图片转换成svg格式private void convert(String file,String dest) throws Exception{InputStream in = new FileInputStream(file);WmfParser parser = new WmfParser();final SvgGdi gdi = new SvgGdi(false);parser.parse(in, gdi);Document doc = gdi.getDocument();OutputStream out = new FileOutputStream(dest);if (dest.endsWith(".svgz")) {out = new GZIPOutputStream(out);}output(doc, out);}private void output(Document doc, OutputStream out) throws Exception {TransformerFactory factory = TransformerFactory.newInstance();Transformer transformer = factory.newTransformer();transformer.setOutputProperty(OutputKeys.METHOD, "xml");transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");transformer.setOutputProperty(OutputKeys.INDENT, "yes");transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,"-//W3C//DTD SVG 1.0//EN");transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");transformer.transform(new DOMSource(doc), new StreamResult(out));ByteArrayOutputStream bos = new ByteArrayOutputStream();transformer.transform(new DOMSource(doc), new StreamResult(bos));out.flush();out.close();}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。