绍金解易经八字揭秘epub 绍金解易经八字揭秘txt

频道:八字 日期: 浏览:2

Aspose.Words可以在没有安装Microsoft Office的机器上工作。所有的Aspose组件都是独立,不需要微软公司的授权。总之, Aspose.Words在安全性、稳定性、可扩展性、速度、价格和自动化功能方面,是一个很不错的选择。

下面一起来学习一下

一、环境搭建

1、首先需要下载一个aspose插件jar包放进项目中,使用的IDEA,jar包可以在网盘下载:  链接:https://pan.baidu.com/s/1jISO-TPEyLgC8RTmMJGRQw 提取码:9ju82、下载好所需要的jar包,idea需要引入jar包,从编译的层面考虑将将jar包安装到本地仓库,解决编译打包时出错的问题。  A.首先确定 mvn -v 能否使用,将下载好的jar包放到项目外的本地文件夹。  B.其次执行mvn install 安装本地jar包到本地仓库,如下所示:mvn install:install-file -DgroupId=com.aspose -DartifactId=aspose-words -Dversion=15.8.0 -Dpackaging=jar -Dfile=aspose-words-15.8.0-jdk16.jar

 执行完成后可到本地仓库查看是否有这个包存在即可。3、在项目中添加对本地仓库的依赖:<dependency><groupId>com.aspose</groupId><artifactId>aspose-words</artifactId><version>15.8.0</version></dependency>

二、添加license文件

在可以读取到的地方,springboot中需要放入resource/static文件下

<?xml version="1.0" encoding="UTF-8" ?><License> <Data> <Products> <Product>Aspose.Total for Java</Product> <Product>Aspose.Words for Java</Product> </Products> <EditionType>Enterprise</EditionType> <SubscriptionExpiry>20991231</SubscriptionExpiry> <LicenseExpiry>20991231</LicenseExpiry> <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber> </Data> <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>

三、创建工具类package com.ruoyi.system.utils;import com.aspose.words.Document;import com.aspose.words.License;import com.aspose.words.SaveFormat;import java.io.*;public class Word2PdfAsposeUtil { public static boolean getLicense(InputStream is) { boolean result = false; try { License aposeLic = new License(); aposeLic.setLicense(is); result = true; } catch (Exception e) { e.printStackTrace(); }finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; } public static boolean doc2pdf(InputStream license,String inPath, String outPath,int type) { if(license!=null){ if (!getLicense(license)) { // 验证License 若不验证则转化出的pdf文档会有水印产生 return false; } } FileOutputStream os = null; try { long old = System.currentTimeMillis(); File file = new File(outPath); // 新建一个空白pdf文档 os = new FileOutputStream(file); Document doc = new Document(inPath); // Address是将要被转化的word文档 doc.save(os, type);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, // EPUB, XPS, SWF 相互转换 long now = System.currentTimeMillis(); System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); // 转化用时 } catch (Exception e) { e.printStackTrace(); return false; }finally { if (os != null) { try { os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; } public static void main(String[] arg) throws FileNotFoundException { File file = new File("D:\\license.xml"); InputStream is = new FileInputStream(file); String docPath = "D:\\生产环境部署手册.docx"; String pdfPath = "D:\\生产环境部署手册.pdf"; String htmlPath = "D:\\生产环境部署手册.html"; String JPEGPath = "D:\\生产环境部署手册.JPEG"; // int type =SaveFormat.PDF;//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, // Word2PdfAsposeUtil.doc2pdf(is,docPath,pdfPath,type); // int html=SaveFormat.HTML; // Word2PdfAsposeUtil.doc2pdf(is,docPath,htmlPath,html); int docx = SaveFormat.JPEG; // Word2PdfAsposeUtil.doc2pdf(is,htmlPath,JPEGPath,SaveFormat.JPEG);//HTML转图片 // Word2PdfAsposeUtil.doc2pdf(is,htmlPath,docPath,SaveFormat.DOCX); Word2PdfAsposeUtil.doc2pdf(is,pdfPath,docPath,SaveFormat.JPEG); }}四、sprincloud中测试@GetMapping("/common/test") public Boolean test(String fileName,String wordPath,String pdfPath){ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("static/license.xml"); String docPath = "D:\\生产环境部署手册.docx"; String pdfPath = "D:\\生产环境部署手册.pdf"; String htmlPath = "D:\\生产环境部署手册.html"; String JPEGPath = "D:\\生产环境部署手册.JPEG"; // int type =SaveFormat.PDF;//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, // Word2PdfAsposeUtil.doc2pdf(is,docPath,pdfPath,type); // int html=SaveFormat.HTML; // Word2PdfAsposeUtil.doc2pdf(is,docPath,htmlPath,html); int docx = SaveFormat.JPEG; // Word2PdfAsposeUtil.doc2pdf(is,htmlPath,JPEGPath,SaveFormat.JPEG);//HTML转图片 // Word2PdfAsposeUtil.doc2pdf(is,htmlPath,docPath,SaveFormat.DOCX); Word2PdfAsposeUtil.doc2pdf(is,pdfPath,docPath,SaveFormat.JPEG);}

代码截图

绍金解易经八字揭秘epub