做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();}