羃使用jacob将word转成PDF蒀 肁上面的这篇文章使用jacob将word转换成HTML的,利用的是Word的另存为功能,在Office2007SP2之后,Office就可以另存为PDF了,可以使用这个方法将office另存为PDF文档。蚆 芅具体代码可以参考上文里面的,另存为哪种类型是由newvariant()里面的参数决定的。膃 薇 (doc, "SaveAs", , new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]); 螇newVariant(),这里面的根据传入的参数不同,可以另存为不同的类型,但是在网上搜索了一个并没有找到有关这个参数类型的一个说明,自己尝试了一下,结果如下:蒄 薃 莈0蒅Doc薂1肂Dot肈2-5薆Txt袅6蒁Rtf螈7蚈Txt肃8、10袁htm蕿11蒅Xml莅12、16芀Docx艿13蒆Docm蒄14羃Dotx聿15薈Dotm蚂17蒃Pdf螀 莅我使用的是office2010,不同版本的对应的应该不一样,我是写了这一小段程序来测试另存为的类型的。羄 袂Java代码 薀public class JacobTest { 莆 public static void wordToPDF(String docfile, String toFile,int type) { 肃 ponent app = new ponent(""); // 启动word 节 try { 芁 ("Visible", new Variant(false)); 蒈 Dispatch docs = ("Documents").toDispatch(); 蒅 Dispatch doc = ( 蚁 docs, 羁 "Open", 芅 , new Object[] { docfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch(); //new Variant(type),这里面的type的决定另存为什么类型的文件 (doc, "SaveAs", , new Object[] { toFile, new Variant(type) }, new int[1]); Variant f = new Variant(false);
使用jacob将word转成PDF 来自淘豆网m.daumloan.com转载请标明出处.