aspose简述

Aspose.Total是Aspose公司旗下的最全的一套office文档管理方案,主要提供.net跟java两个开发语言的控件套包,通过它,我们可以有计划地操纵一些商业中最流行的文件格式:Word, Excel, PowerPoint, Project,等office文档以及PDF文档。如需下载aspose.total官方网址:https://downloads.aspose.com/total/

  • 以下这是基于java语言版的,如果需要.net语言的可以去官网参考学习。

文档转换实现示例代码(部分代码来自于网络)

aspose下载或许需要一些条件。以下附上早期版链接:https://pan.baidu.com/s/1u4Q2DHiw-6GAPo-Jj8rTGQ
提取码:cwk5

package test;import java.io.File;
import java.io.FileOutputStream;import com.aspose.pdf.DocSaveOptions;
import com.aspose.pdf.Document;
import com.aspose.pdf.ExcelSaveOptions;
import com.aspose.pdf.PptxSaveOptions;
import com.aspose.pdf.SaveFormat;public class PdfToOthers {WordToOthers conv=new WordToOthers();fileDomainVO vo=new fileDomainVO();public fileDomainVO PdfToOthers(fileDomainVO vo) {vo.setStatus(Details.FailStatus);
//          if(!conv.getLicense()) {
//              System.out.println("验证失败,产生水印!");
//          }Document doc=null;try {//统计时间long old = System.currentTimeMillis();doc=new Document(vo.getInputfile());//创建一个空白文件夹File file=null;FileOutputStream os=null;file = new File(vo.getOutputfile());  //创建文件夹file.mkdirs();file = new File(vo.getOutputfile()+vo.getFileNameAfter());  os = new FileOutputStream(file);if(vo.getDetails().equals(Details.PdfToDocx)){DocSaveOptions saveOptions =  new  DocSaveOptions();saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);doc.save(os,SaveFormat.DocX);System.out.println("转换完成!");}else if(vo.getDetails().equals(Details.PdfToExcel)) {ExcelSaveOptions saveOptions =  new  ExcelSaveOptions();doc.save(os,saveOptions);System.out.println("转换完成");}else if(vo.getDetails().equals(Details.PdfToPpt)) {PptxSaveOptions saveoptions=new PptxSaveOptions();doc.save(os,saveoptions);System.out.println("转换完成");}long now = System.currentTimeMillis();//System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"+"文件保存在:" + vo.getOutputfile());//设置时间vo.setTimeConsuming((((now - old) / 1000.0)+"").trim());//成功vo.setStatus(Details.SuccessStatus);}catch(Exception e) {e.printStackTrace();}return vo;}
}
package test;import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;import junit.framework.Test;  public class WordToOthers {/*** 验证License* @return boolean*/public static boolean getLicense() {boolean result = false;try {//license.xml//如果不知道应该放在哪个路径,就在控制台打印一下,然后去放就好啦
//            System.out.println(Test.class.getClassLoader().getResource("").getPath());InputStream is = Test.class.getClassLoader().getResourceAsStream("license.xml");                License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** word转换* 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换* @param */public  fileDomainVO WordToOthers(fileDomainVO vo) {//默认失败vo.setStatus(Details.FailStatus);if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生System.out.println("验证失败,会产生水印");}//创建一个doc对象Document doc =null;try {//统计时间long old = System.currentTimeMillis();//初始化定义File file =null;ImageSaveOptions iso = null;//输出流FileOutputStream os =null;//判断是否转换图片if(vo.getDetails().equals(Details.DocToJPEG)){iso = new ImageSaveOptions(SaveFormat.JPEG); }else{//file.mkdirs();//新建一个空白文档file = new File(vo.getOutputfile());  //创建文件夹file.mkdirs();file = new File(vo.getOutputfile()+vo.getFileNameAfter());  os = new FileOutputStream(file);}//getInputfile是将要被转化文档          doc = new Document(vo.getInputfile());    //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换//------------------------------------------逻辑判断//>>>>>>DocToPDFif(vo.getDetails().equals(Details.DocToPDF)){doc.save(os, SaveFormat.PDF);   }//>>>>>>DocToDocxelse if(vo.getDetails().equals(Details.DocToDocx)){doc.save(os, SaveFormat.DOCX);}//>>>>>>DocToTexTelse if(vo.getDetails().equals(Details.DocToTexT)){doc.save(os, SaveFormat.TEXT);}//>>>>>>DocToXpselse if(vo.getDetails().equals(Details.DocToXps)){doc.save(os, SaveFormat.XPS);}//>>>>>>HtmlToDocelse if(vo.getDetails().equals(Details.HtmlToDoc)){doc.save(os, SaveFormat.DOC);}//>>>>>>DocToJPEGelse if(vo.getDetails().equals(Details.DocxToDoc)) {doc.save(os,SaveFormat.DOC);}else if(vo.getDetails().equals(Details.DocxToPDF)) {doc.save(os,SaveFormat.PDF);}else if(vo.getDetails().equals(Details.DocToJPEG)){iso.setPrettyFormat(true);iso.setUseAntiAliasing(true);for (int i = 0; i < doc.getPageCount(); i++){iso.setPageIndex(i);doc.save(vo.getOutputfile() + vo.getFileNameAfter() +"---"+(i+1)+ ".jpeg", iso);}  }//------------------------------------------逻辑判断//统计时间long now = System.currentTimeMillis();//System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"+"文件保存在:" + vo.getOutputfile());//设置时间vo.setTimeConsuming((((now - old) / 1000.0)+"").trim());//成功vo.setStatus(Details.SuccessStatus);} catch (Exception e) {e.printStackTrace();}return vo;}}
package test;import java.sql.Date;public class   fileDomainVO {//创建fileDomainVO实体类//复制好后,记得添加set,get方法private Integer id;private Date time;  //操作时间private String filename;  //原文件名private String fileNameAfter;  //转换后文件名private String filesize;   //原文件大小private String filetype;   //原文件类型private String filetypeafter;  //后文件类型private String details;     //操作详情private String outputfile;  //保存路径private String inputfile;   //原文件路径 private Integer pageno;private Integer pages;private Integer rid;private Integer pageoperation;private Integer pagestart;private Integer pageend;private String fileSizeAfter;  //后  文件大小private Integer status;  //操作状态private Integer afterpages;private String detail;  private String timeConsuming; //消耗时长public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Date getTime() {return time;}public void setTime(Date time) {this.time = time;}public String getFilename() {return filename;}public void setFilename(String filename) {this.filename = filename;}public String getFileNameAfter() {return fileNameAfter;}public void setFileNameAfter(String fileNameAfter) {this.fileNameAfter = fileNameAfter;}public String getFilesize() {return filesize;}public void setFilesize(String filesize) {this.filesize = filesize;}public String getFiletype() {return filetype;}public void setFiletype(String filetype) {this.filetype = filetype;}public String getFiletypeafter() {return filetypeafter;}public void setFiletypeafter(String filetypeafter) {this.filetypeafter = filetypeafter;}public String getDetails() {return details;}public void setDetails(String details) {this.details = details;}public String getOutputfile() {return outputfile;}public void setOutputfile(String outputfile) {this.outputfile = outputfile;}public String getInputfile() {return inputfile;}public void setInputfile(String inputfile) {this.inputfile = inputfile;}public Integer getPageno() {return pageno;}public void setPageno(Integer pageno) {this.pageno = pageno;}public Integer getPages() {return pages;}public void setPages(Integer pages) {this.pages = pages;}public Integer getRid() {return rid;}public void setRid(Integer rid) {this.rid = rid;}public Integer getPageoperation() {return pageoperation;}public void setPageoperation(Integer pageoperation) {this.pageoperation = pageoperation;}public Integer getPagestart() {return pagestart;}public void setPagestart(Integer pagestart) {this.pagestart = pagestart;}public Integer getPageend() {return pageend;}public void setPageend(Integer pageend) {this.pageend = pageend;}public String getFileSizeAfter() {return fileSizeAfter;}public void setFileSizeAfter(String fileSizeAfter) {this.fileSizeAfter = fileSizeAfter;}public Integer getStatus() {return status;}public void setStatus(Integer status) {this.status = status;}public Integer getAfterpages() {return afterpages;}public void setAfterpages(Integer afterpages) {this.afterpages = afterpages;}public String getDetail() {return detail;}public void setDetail(String detail) {this.detail = detail;}public String getTimeConsuming() {return timeConsuming;}public void setTimeConsuming(String timeConsuming) {this.timeConsuming = timeConsuming;}}
package test;import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;import junit.framework.Test;public class ExcleToPdf {/*** 验证License* @return boolean*/public static boolean getLicense() {boolean result = false;try {//license.xml//如果不知道应该放在哪个路径,就在控制台打印一下,然后去放就好啦
//            System.out.println(Test.class.getClassLoader().getResource("").getPath());InputStream is = Test.class.getClassLoader().getResourceAsStream("license.xml");                License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}return result;} /*** * @param excel转换* @return*/public   fileDomainVO  excelToPdf(fileDomainVO vo){vo.setStatus(Details.FailStatus);if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生System.out.println("验证失败,会产生水印");return vo;}try {//统计时间long old=System.currentTimeMillis();//创建一个空白文件夹File file=null;Workbook wb=null;FileOutputStream os=null;file = new File(vo.getOutputfile());  //创建文件夹file.mkdirs();file = new File(vo.getOutputfile()+vo.getFileNameAfter());  os = new FileOutputStream(file);System.out.println(file);System.out.println(os);wb=new Workbook(vo.getInputfile());if(vo.getDetails().equals(Details.ExcelToPDF)) {System.out.println(vo.getDetails().equals(Details.ExcelToPDF));wb.save(os,SaveFormat.PDF);System.out.println(com.aspose.cells.SaveFormat.PDF);os.close();}long now = System.currentTimeMillis();System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"+"文件保存在:" + vo.getOutputfile()+vo.getFileNameAfter());//设置时间vo.setTimeConsuming((((now - old) / 1000.0)+"").trim());//成功vo.setStatus(Details.SuccessStatus);}catch(Exception e){e.printStackTrace();}return vo;}
}
package test;public class Main {public static void main(String[] args) throws Exception {fileDomainVO vo = new fileDomainVO();WordToOthers Conv=new WordToOthers();ExcleToPdf extp=new ExcleToPdf();PdfToOthers pdfto=new PdfToOthers();/***     进行PDF转PPT格式测试   *   测试通过*/
//         vo.setDetails(Details.PdfToPpt);
//         vo.setInputfile("d:/test/2019.pdf");
//         vo.setOutputfile("d:/test/");
//         vo.setFileNameAfter("exclename.pptx");//         /**
//          *   进行PDF转docx格式测试
//          *   测试通过
//          */
//        vo.setDetails(Details.PdfToDocx);
//        vo.setInputfile("E:/myfiles/bigdata/个人学习/Hive编程指南.pdf");
//        vo.setOutputfile("E:/myfiles/bigdata/个人学习/");
//        vo.setFileNameAfter("Hive.docx");
//        pdfto.PdfToOthers(vo);/***    进行word转PDF测试*   测试通过
//          */
//         vo.setDetails(Details.DocxToPDF);     //进行word转pdf
//         vo.setInputfile("D:/test/name.doc");       //需要转换的word
//         vo.setOutputfile("D:/test/");         //保存路径
//         vo.setFileNameAfter("name.pdf");
//         Conv.WordToOthers(vo);                           //开始转换/***   进行excel转PDF测试* 测试通过*/
//         vo.setDetails(Details.ExcelToPDF);//进行excel转PDF
//         vo.setInputfile("D:/test/123.xlsx");       //需要转换的word
//         vo.setOutputfile("D:/test/");         //保存路径
//         vo.setFileNameAfter("1.pdf");
//         extp.excelToPdf(vo);/***     进行PDF转Word测试*   使用PDFbox包能将PDF上的文字全部转换为Word但是不能保持原有样式*  测试通过*   不推荐使用*/vo.setInputfile("E:/myfiles/bigdata/个人学习/Hadoop权威指南_第四版_中文版.pdf");       //需要转换的wordvo.setOutputfile("E:/myfiles/bigdata/个人学习/");         //保存路径vo.setFileNameAfter("HADOOP权威.doc");           //转换后的文件名,自己取}
}
package test;public class Details {public static Integer SuccessStatus=0;        //状态:成功public static Integer FailStatus=1;           //状态:失败public static String DocToPDF="DocToPDF";     public static String DocToDocx="DocToDocx";public static String DocToTexT="DocToTexT";public static String DocToXps="DocToXps";public static String HtmlToDoc="HtmlToDoc";public static String DocToJPEG="DocToJPEG";public static String DocxToDoc="DocxToDoc";public static String DocxToPDF="DocxToPDF";public static String ExcelToPDF="ExcelToPDF";//       PDF转换为其他的格式定义public static String PdfToDocx="PdfToDocx";public static String PdfToExcel="PdfToExcel";public static String PdfToPpt="PdfToPpt";public static String PdfTojpg="PdfTojpg";
}
<?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>

以上测试基本通过,转换时如是PDF转Word如不需图片之类用PDFbox包即可解决,且效果不错,有其他参数参与的用aspose.Words效果较好。使用转换图片类型的PDF文件效果较差,不推荐。

java通过aspose实现文档间格式转换相关推荐

  1. Java——EasyPoi导出word文档,itextpdf转换pdf

    EasyPoi导出word文档,itextpdf转换pdf 文章目录 EasyPoi导出word文档,itextpdf转换pdf 前言 一.依赖 二.工具类 1.WordUtil 2.PDF工具类 3 ...

  2. Java使用Aspose组件进行多文档间的转换操作

    什么是Aspose? Aspose.Total是Aspose公司旗下的最全的一套office文档管理方案,主要提供.net跟java两个开发语言的控件套包,通过它,我们可以有计划地操纵一些商业中最流行 ...

  3. word文档doc格式转换成docx

    把doc格式转换成docx jar包下载 //把doc格式转换成docx//导入 Spire.Doc.jarDocument d = new Document("F:\\**\\**\\云想 ...

  4. 将html格式文档带格式转换,如何将HTML转换为文档格式?

    我希望能够将HTML转换为docx或RTF.有很多用于创建docx和RTF文档的Ruby gems,但它们只是用于创建一个空文档,然后您可以通过编程添加内容.如何将HTML转换为文档格式? 这些宝石的 ...

  5. Word处理控件Aspose.Words功能演示:使用Java合并MS Word文档

    在各种情况下,可能需要合并多个MS Word文档,例如减少文档数量,在单个文件中保留相似种类的内容(即发票)等.许多在线应用程序使您可以合并两个或多个MS Word文档但是,您可能需要在自己的Web或 ...

  6. Word处理控件Aspose.Words功能演示:使用 Java 在 MS Word 文档中进行邮件合并

    Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此 ...

  7. Word处理控件Aspose.Words功能演示:使用 Java 比较 MS Word 文档

    Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此 ...

  8. Word处理控件Aspose.Words功能演示:使用 Java 拆分 MS Word 文档

    Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此 ...

  9. Word处理控件Aspose.Words功能演示:使用Java在MS Word文档中进行邮件合并

    邮件合并是一种动态生成信件,信封,发票,报告和其他类型文档的便捷方法.使用邮件合并,您可以创建一个包含合并字段的模板文件,然后使用数据源中的数据填充这些字段. 假设您必须向20个不同的人发送一封信,并 ...

最新文章

  1. android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画...
  2. Java 分割字符串的方法String.split()底层原理
  3. oracle学习之三--多表查询
  4. Basic--Java基本语法
  5. 学车是学手动档好,还是学自动档好呢?另外建议自驾游选哪个档比较好呢?
  6. 手机qq和电脑qq怎么同步消息_怎么在QQ上把自己电脑上的文件传到QQ上??
  7. iOS利用代理实现界面跳转
  8. 基于python语言开发的员工信息管理系统
  9. 两矩阵相乘的秩的性质_矩阵分析与应用(一,矩阵基础知识)
  10. 防火墙、防病毒网关、IDS以及该类安全产品开发
  11. CenterOs操作
  12. FS7022双节锂电池8.4V保护IC电路图
  13. c语言结构体的流程图怎么画,结构流程图不会画?手把手教你学会!
  14. 小学英语之拯救小学生 V1.0 名词单复数变化规则
  15. HP Gen8 MicroServer win7 系统安装手册(usb)
  16. Rhythmbox中文乱码解决办法
  17. Halcon学习-算子学习-映射/傅里叶变换/gen_grid_region/rft_generic例程
  18. 一名中专生的坎坷程序人生(下)
  19. 中央大学计算机学什么,中央大学
  20. MySQL多表查询大全(超精确)

热门文章

  1. 阿里推出新品牌“瓴羊”,致力成为“数字化领头羊”
  2. 关于微信防撤回(文本、图片、语音、视频、名片等...)的Python学习教程
  3. 二、解线性方程组的直接方法
  4. 被骂了十年的国产软件,却成了世界之最...
  5. 身份证 闰年验证 超强验证
  6. yy欢聚时代软件测试笔试题
  7. 京东区块链之供应链应用篇:溯源应用结合区块链能碰撞出什么火花?
  8. powerquery分组,PowerQuery:如何连接分组值?
  9. ClickHouse settings final
  10. lsdyna进阶教程-弹性球撞击刚性平板