java实现word转pdf aspose

您所在的位置:网站首页 java实现word转pdf java实现word转pdf aspose

java实现word转pdf aspose

2023-03-23 06:05| 来源: 网络整理| 查看: 265

本文共 1667 字,大约阅读时间需要 5 分钟。

导入jar包aspose-words-15.8.0-jdk16.jar 校验license.xml文件

public static boolean getLicense() {    boolean result = false;try {    InputStream is = WordToPdfUtils.class.getClassLoader().getResourceAsStream("license.xml"); //  license.xml应放在..\WebRoot\WEB-INF\classes路径下License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {    e.printStackTrace();}return result;} /** * word转pdf * @param Address word路径 */public static String doc2pdf(String Address) {    String outPath="";if (!getLicense()) {  // 验证License 若不验证则转化出的pdf文档会有水印产生return null;}try {      outPath="C:/Users/Administrator/Desktop/1.pdf"; //文件输出位置long old = System.currentTimeMillis();File file = new File(outPath);  //新建一个空白pdf文档FileOutputStream os = new FileOutputStream(file);Document doc = new Document(Address);//Address是将要被转化的word文档//insertWatermarkText(doc, "水印内容");//设置水印doc.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换os.close();long now = System.currentTimeMillis();System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");  //转化用时} catch (Exception e) {    e.printStackTrace();}return outPath;}

创建License.xml文件

Aspose.Total for Java Aspose.Words for Java Enterprise 20991231 20991231 8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7 sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=

转载地址:https://blog.csdn.net/z_hongchang/article/details/119892208 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3