当前位置: 首页 > news >正文

广州网站设计提供商建设自己网站

广州网站设计提供商,建设自己网站,html5模板下载,天将建设集团有限公司网站背景: 最近做的一个项目中,对于word转Pdf用的地方很多,特此记录 搭建总图: 代码部分: 1.需要的jar包: aspose-words-15.8.0-jdk16.jar 注:下载好这个jar包后,在项目的根目录新建一…

背景:

    最近做的一个项目中,对于word转Pdf用的地方很多,特此记录

搭建总图:

 代码部分:

 1.需要的jar包:

aspose-words-15.8.0-jdk16.jar

注:下载好这个jar包后,在项目的根目录新建一个lib文件夹,然后放入该jar包

pom.xml中引用

<dependency><groupId>com.aspose-words-15.8.0-jdk16</groupId><artifactId>aspose-words-15.8.0-jdk16</artifactId><version>1.0.0</version><scope>system</scope><systemPath>${project.basedir}/lib/aspose-words-15.8.0-jdk16.jar</systemPath>
</dependency>

  2.需要的xml文件

license.xml

内容:

<?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>

 注:将该xml文件放到resources下面

 3.工具类

import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.*;
import java.io.File;
import java.io.IOException;public class WordConvertPdf {public static boolean getLicense() {boolean result = false;InputStream is = null;try {Resource resource = new ClassPathResource("license.xml");is = resource.getInputStream();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(String inPath, String outPath) {if (!getLicense()) { // 验证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, SaveFormat.PDF);// 全面支持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){String docPath = "E:\\syp.doc";String pdfPath = "E:\\ceshi.pdf";doc2pdf(docPath,pdfPath);}
}

测试结果:

 

http://www.yayakq.cn/news/902165/

相关文章:

  • 软件公司网站素材郝友做的网站
  • 新开传奇网站手机版自建网站怎么做推广
  • 网站建设方式与信息化青鸟网站开发实例
  • 17做网店官网荆门seo
  • 做的网站百度找不到了东莞保安公司哪家好
  • 滁州网站建设费用网络推广是以企业产品或服务
  • 如何建设一个普通网页网站常用的软件开发文档
  • 西安商城网站搭建企业建网站需要准备哪些资料呢
  • 网站单页在线学编程去哪里学比较好
  • 玛纳斯县住房和城乡建设局网站wordpress按钮插件
  • 太原网站建设方案咨询可以直接打开网站的网页
  • 沈阳网站建设 景乔科技网站做APP麻烦吗
  • 北京免费建站深圳市点击未来科技网站建设
  • 上海网站建设解决方案免费新闻源发布平台
  • 表白网站怎么做祁东seo公司
  • 创建网站成功案例建设银行信用卡管理中心网站首页
  • 提供东莞微信网站建设wordpress符号插件
  • 三门峡高端网站建设打电话沟通做网站话术
  • 网站建设基本问题wordpress子主题
  • 住房和城乡建设部网站北京网站建设高校
  • 买了域名怎么做网站南通网站制作怎样
  • 做电影网站会不会涉及版权问题易营宝智能建站平台
  • cms网站栏目介绍网站建设基础考试
  • 网站内链怎么删除wordpress自定义页眉设置
  • 临海网站设计网页图片显示不出来打叉
  • 带视频的网站模板wordpress教学视屏
  • 为什么有的网站只有版权没有备案网站兼容性怎么调
  • 网站建设工作人员有哪些职责网站备案入口
  • 惠州seo网站管理中牟建设局网站
  • 公司微网站制作wordpress登录开发