优化网站制作,南京网站开发公司排名,二级域名分发网站,谈期刊网站建设第一种#xff1a;使用spire.doc.jar包#xff0c;用时7秒左右。 引入spire.doc-11.1.1.jar包#xff0c;该包带水印#xff0c;建议使用免费版的spire.doc.free-5.2.0.jar#xff0c;免费版只能转三页。
package web.tools.excel;
import com.spire.doc.*; public cl…第一种使用spire.doc.jar包用时7秒左右。 引入spire.doc-11.1.1.jar包该包带水印建议使用免费版的spire.doc.free-5.2.0.jar免费版只能转三页。
package web.tools.excel;
import com.spire.doc.*; public class test { public static void main(String[] args) { Document doc new Document(); doc.loadFromFile(D:/Backup/Downloads/我的源文件.docx); doc.saveToFile(D:/Backup/Downloads/输出文件.pdf, FileFormat.PDF); doc.close(); System.out.println(转化完毕-----------------------); }
} 第二种使用aspose-words-15.8.0-jdk16.jar包用时3秒左右。 /** * 将word文档转为PDF后输出 * 烟雨江南 * param urlIn word文档所在全路径 ;dir输出文档的目录 * return */ public static String wordToPdf(String urlIn,String dir){ String url; try { //自定义新文件名 SimpleDateFormat sdf1 new SimpleDateFormat(yyyy-MM-dd-HH-mm); long dateTime new Date().getTime(); String currentTimestr sdf1.format(dateTime); String newFileName currentTimestr - suiJishu() .pdf; urldir/newFileName; // String s LicenseDataProductsProductAspose.Total for Java/Product ByteArrayInputStream is new ByteArrayInputStream(s.getBytes()); License license new License(); license.setLicense(is); com.aspose.words.Document document new com.aspose.words.Document(urlIn); File filenew File(url); FileOutputStream outnew FileOutputStream(file); document.save(out,SaveFormat.PDF); out.close(); } catch (Exception e) { e.printStackTrace(); } return url; } 备注jar包可以在我资源库下载