xml转换为word xml文件转换成word
xml文件怎么转换成word 知乎
通过jodconveter来实现转化(http://www.artofsolving.com/opensource/jodconverter)。
这种方式实现起来比较麻烦,操作有点繁琐,但是能解决上述问题。
通过启动OpenOffice.org的服务端口,实现程序操作opeanoffice实现文件的转换。
贴上代码:mport java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.DocumentFormatRegistry; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; public class test { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub test t = new test(); //File in = new File("d:\\mytest\\test1.pdf"); //File out = new File("d:\\mytest\\test11.html"); FileInputStream input = new FileInputStream("d:\\mytest\\test11.pdf"); FileOutputStream output = new FileOutputStream("d:\\mytest\\test11.doc"); t.convert(input, output); } public void convert(File input, File output) throws Exception { OpenOfficeConnection conn = new SocketOpenOfficeConnection("localhost", 8100); conn.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(conn); converter.convert(input, output); conn.disconnect(); } public void convert(InputStream input, OutputStream output) throws Exception { OpenOfficeConnection conn = new SocketOpenOfficeConnection("localhost", 8100); conn.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(conn); DocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); converter.convert(input, registry.getFormatByFileExtension("pdf"), output, registry.getFormatByFileExtension("doc")); conn.disconnect(); } }
怎么把XML变成WORD文档?
aspose的官网上查了下文档,Aspose.PDF无法直接转换word文档,需要先有个中间步骤。
就是先把word转换成XML格式的文件,再使用Aspose.PDF绑定这个XML Aspose.PDF不能将word文件转换成PDF文件,因此就会出现aspose把word文档转换为pdf文档时出现乱码情况,再保存为PDF格式...
-