嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
aspose-words-19.5jdk 破解文件仅供学习交流,不得用于商业用途,商业通途请购买正版aspose
package com.example.demo;
import java.io.File;
import java.io.FileOutputStream;
import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;
public class DocDemo {
public static void doc2pdf(String inPath, String outPath) throws Exception {
// 验证License 若不验证则转化出的pdf文档有水印
// if (!checkLicense()) {
// throw new Exception("com.aspose.words lic ERROR!");
// }
System.out.println(inPath " -> " outPath);
FileOutputStream os = null;
try {
long old = System.currentTimeMillis();
File file = new File(outPath);
os = new FileOutputStream(file);
Document doc = new Document(inPath); // word文档
int pageCount = doc.getPageCount();
System.out.println("pagecount: " pageCount);
// 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换
doc.save(os, SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("convert OK! " ((now - old) / 1000.0) "秒");
} catch (Exception e) {
e.printStackTrace();
}finally{
if(os!=null){
try{
os.flush();
os.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
public static void doc2JPEG(String inPath, String imgDictory) throws Exception{
try {
long old = System.currentTimeMillis();
Document doc = new Document(inPath); // word文档
int pageCount = doc.getPageCount();
File f = new File(imgDictory);
if (!f.exists()) {
f.mkdir();
}
ImageSaveOptions op = new ImageSaveOptions(SaveFormat.JPEG);
op.setPrettyFormat(false);
for (int page = 0; page < pageCount; page ){
FileOutputStream os = null;
try{
os = new FileOutputStream(imgDictory "\\" page ".jpeg");
op.setPageIndex(page);
doc.save(os, op);
}catch(Exception ex){
System.out.println("save error.");
ex.printStackTrace();
}finally{
if(os!=null){
try{
os.flush();
os.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
long now = System.currentTimeMillis();
System.out.println("convert OK! " ((now - old) / 1000.0) "秒");
} catch (Exception e) {
e.printStackTrace();
}
}
}