office转pdf实现office在线预览(aspose)

  • 1. jar包地址
  • 2. 将jar包安装到本地
  • 3. pom文件添加依赖
  • 4. license.xml
    • ① license.xml存放路径
    • ② license.xml代码内容
  • 5. 工具类 AsposeUtil

1. jar包地址

链接: 百度云下载链接
提取码: 630z

2. 将jar包安装到本地

maven安装本地依赖教程

3. pom文件添加依赖

注:此处aspose版本为上一部安装到本地仓库的版本

            <dependency><groupId>com.aspose</groupId><artifactId>aspose-cells</artifactId><version>${aspose-cells.version}</version></dependency><dependency><groupId>com.aspose</groupId><artifactId>aspose-words</artifactId><version>${aspose-words.version}</version></dependency><dependency><groupId>com.aspose</groupId><artifactId>aspose-slides</artifactId><version>${aspose-slides.version}</version></dependency>

4. license.xml

① license.xml存放路径

license.xml为水印破解,放在resources下,第四步中工具类中需要读取文件内容

② license.xml代码内容

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

5. 工具类 AsposeUtil

package com.package.name;import com.aspose.cells.PaperSizeType;
import com.aspose.cells.Workbook;
import com.aspose.slides.Presentation;
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;import java.io.*;public class AsposeUtil {public static void main(String[] args) throws Exception {AsposeUtil bean = new AsposeUtil();bean.word2Pdf2("D:\\pdf\\12.docx","D:\\pdf\\12.pdf");;}/*** 验证License 若不验证则转化出的pdf文档会有水印产生* @return*/public  boolean getLicense() {boolean result = false;try {//引入license.xml文件,去除水印InputStream is =this.getClass().getClassLoader().getResourceAsStream("static/license.xml");//注意此处为apose-slides的jar包License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** 验证License 若不验证则转化出的pdf文档会有水印产生* @return*/public  boolean getLicenseExcel() {boolean result = false;try {InputStream is =this.getClass().getClassLoader().getResourceAsStream("static/license.xml");//注意此处为对应aspose-cells的jar包com.aspose.cells.License aposeLic = new com.aspose.cells.License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** 验证License 若不验证则转化出的pdf文档会有水印产生* @return*/public boolean getLicensePpt(){boolean result = false;try {InputStream is =this.getClass().getClassLoader().getResourceAsStream("static/license.xml");//注意此处为对应aspose-slides的jar包com.aspose.slides.License aposeLic = new com.aspose.slides.License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** word转pdf* inpath: 输入word的路径* outpath: 输出pdf的路径*/public  void word2Pdf2(String inpath,String outpath) throws Exception {if (!getLicense()) {System.out.println("非法------------");return;}long old = System.currentTimeMillis();File file = new File(outpath);FileOutputStream os = new FileOutputStream(file);//解决乱码//如果是windows执行,不需要加这个//TODO 如果是linux执行,需要添加这个*****//FontSettings.setFontsFolder("/usr/share/fonts",true);Document doc = new Document(inpath);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换doc.save(os, SaveFormat.PDF);long now = System.currentTimeMillis();System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");}/*** word转pdf* @param path      pdf输出路径* @param wordInput word输入流* @param wordName  word文档的名称*/public  void word2pdf(String path, InputStream wordInput, String wordName) throws FileNotFoundException {if (!getLicense()) {System.out.println("非法");return;}//新建一个空白pdf文档long old = System.currentTimeMillis();File file = new File(path + wordName + ".pdf");FileOutputStream os = new FileOutputStream(file);//Address是将要被转化的word文档Document doc = null;try {doc = new Document(wordInput);} catch (Exception e) {e.printStackTrace();}try {//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换doc.save(os, SaveFormat.PDF);} catch (Exception e) {e.printStackTrace();}long now = System.currentTimeMillis();//转化用时System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");}public void excel2Pdf(String path,String outpath) throws FileNotFoundException {FileOutputStream fileOutputStream = null;if (!getLicenseExcel()) {System.out.println("非法------------");return;}File file = new File(outpath);try {Workbook wb = new Workbook(path);fileOutputStream= new FileOutputStream(file);//当excel中对应的sheet页宽度太大时,在PDF中会拆断并分页。此处等比缩放。autoDraw(wb);wb.save(fileOutputStream, com.aspose.cells.SaveFormat.PDF);} catch (Exception e) {e.printStackTrace();}finally {try {fileOutputStream.close();} catch (IOException e) {e.printStackTrace();}}}/*** 设置打印的sheet 自动拉伸比例* @param ts*/public void autoDraw(Workbook wb){if(wb.getWorksheets().getCount() > 0){for (int i = 0; i < wb.getWorksheets().getCount(); i++) {wb.getWorksheets().get(i).getPageSetup().setZoom(20);wb.getWorksheets().get(i).getPageSetup().setOrientation(PaperSizeType.PAPER_A_4);}}}public void ppt2Pdf(String path,String outpath)throws FileNotFoundException{if (!getLicensePpt()) {System.out.println("非法------------");return;}File file = new File(outpath);try {Presentation pres = new Presentation(path);//输入pdf路径FileOutputStream fileOS = new FileOutputStream(file);pres.save(fileOS, com.aspose.slides.SaveFormat.Pdf);fileOS.close();} catch (Exception e) {e.printStackTrace();}}
}

office转pdf实现office在线预览(aspose)相关推荐

  1. java对office、pdf文档在线预览解析(融合进项目中)

    最近在项目中要做一个文档的预览,在网上搜了好多demo,都可以实现其功能,但是放在自己的项目中有点复杂. 先说明本人的开发环境(win7+tomcat7+maven+svn+myeclipse),接下 ...

  2. 使用libreoffice将office文档(word、ppt、excel)转pdf,实现在线预览

    项目需要实现局域网预览office文档的功能,之前做的在线项目,都是将文档上传到cdn,利用cdn自带的转码功能,把文档转换为pdf,然后再用pdf.js实现在线预览. 因为是局域网,没有办法上传到c ...

  3. 前端vue实现pdf文件的在线预览

    3.前端vue实现pdf文件的在线预览 我是通过 <iframe> 标签就可以满足我工作的 pdf预览需求 如果<iframe> 无法满足需求 , 可以使用pdf.js这个插件 ...

  4. pdf,word,ppt在线预览

    pdf,word,ppt在线预览 先展示下效果 pdf跟ppt的预览效果: word的预览效果 实现过程-只需一个iframe标签即可 详细介绍请看这里 <iframe src="ht ...

  5. 【aspose】 word/excel转pdf,实现在线预览文件功能

    项目场景: 需求描述:上传附件后,可实现在线预览,这里就会存在一个问题,很多附件的类型是没法在线预览的,点击就会下载.除pdf/jpg/jpeg等,于是技术方案定,将word/excel等类型的文件转 ...

  6. 前端实现docx、pdf格式文件在线预览

    介绍 在业务中,如果遇到文档管理类的功能,会出现需要在线预览的业务需求,本文主要是通过第三方库来实现文档预览功能,并将其封装成preview组件 docx docx的实现需要使用docx-previe ...

  7. 调用office web 365接口实现在线预览word文档,PDF,PPT

    我项目中是直接用iframe显示: <iframe id="iframe_src"  scrolling="auto"  width="100% ...

  8. .net oss存储 oss api接口开发 office文档上传在线预览oss存储 office文档上传oss 阿里云oss接口开发

    word在线预览api接口 office在线预览接口 word转图片 ppt在线预览 excel在线预览 预览支持的文件格式:word(doc,docx),excel(xls,xlsx),ppt(pp ...

  9. 利用Office Online 实现文档在线预览

    首先,office的在线预览无疑问是在不用下载的前提下通过浏览器直接进行浏览,所以针对浏览器的版本不同系统是有要求的,具体的浏览器支持情况可以查看官方提供的文档:点我查看 利用office onlin ...

  10. Office Online Server 文档在线预览编辑【速成篇】

    操作系统 Windows Server 2012 R2 下载地址 密码: h6cq 部署 Office Online Server 官方手册 参照文档 仅执行步骤 1:为 Office Online ...

最新文章

  1. 在AngularJS控制器之间共享数据
  2. Discuz7使用syntaxhighlighter_2.0.320实现代码高亮
  3. python3中的dict循环性能对比
  4. cocos cr躲避类游戏的暂停、继续、重新开始_社团班级团建游戏活动安排
  5. Python黑客入门:暴力破解zip,零基础也可以学会!
  6. priorityqueue 的 add和offer方法有区别吗_日常在家安吉白茶应该如何去保存?城市与农村存放的方法有区别吗...
  7. mysql查询不重复记录数_mysql查询不重复的行内容,不重复的记录数.count,distinct
  8. 钉钉运营商服务器在哪,钉钉应用服务商
  9. 九眼合同智能审核系统运用NLPIR大数据技术进行核查
  10. Family.Show:一个很好玩的东东
  11. eBPF技术应用云原生网络实践:kubernetes网络 | 凌云时刻
  12. ffmpeg生成透明背景视频
  13. 微信中各种代码/符号合集
  14. 18118 勇者斗恶龙(c++ STL sort的运用)
  15. 实验三 XSS和SQL注入
  16. 华为手机使用应用沙盒一键修改电池信息
  17. CSDN编程挑战赛第六期—参赛心得+题解
  18. excel随机数_数据分析常用的excel函数(2)
  19. es6 新增 常用 语法 知识点 汇总
  20. 四级单词pdf_2017年6月大学英语四级真题及答案解析(完整三套可打印)

热门文章

  1. IO输入输出及标准IO函数
  2. JavaWeb验证码登录新闻发布
  3. 这样做生意是亏了还是赚了
  4. python调用sql数据库进存销_python多进程快速批量爬取黄页海量信息并保存文本和数据库教程...
  5. 支付宝安全漏洞(手机号授权相关)
  6. Android 来电拦截的开发实现
  7. DDS QoS -- LIVELINESS
  8. 微信支付-关联商户号申请提交后-解决未授权
  9. 如何将vue项目打包在服务器上运行
  10. android 实现 电话机器人,机器人打电话的原理