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

Aspose.Total是Aspose公司的Office文档管理方案,支持Java和.NET,能处理Word、Excel、PowerPoint等格式。本文介绍Java版的文档转换,提供部分示例代码,并分享了早期版本的下载链接。转换PDF到Word时,若不需要图片,推荐使用PDFbox,而涉及图片的转换,Aspose.Words表现更优。

8956

被折叠的 条评论
为什么被折叠?



