java通过aspose实现文档间格式转换

Aspose.Total是Aspose公司的Office文档管理方案,支持Java和.NET,能处理Word、Excel、PowerPoint等格式。本文介绍Java版的文档转换,提供部分示例代码,并分享了早期版本的下载链接。转换PDF到Word时,若不需要图片,推荐使用PDFbox,而涉及图片的转换,Aspose.Words表现更优。
摘要由CSDN通过智能技术生成
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 boo
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值