package com.wordpdf.common.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.jfinal.core.Controller;
import com.jfinal.kit.PathKit;
import com.jfinal.upload.UploadFile;
public class WordpdfController extends Controller {
private static InputStream license;
private static String word;
public void index(){
renderJsp("zdslist.jsp");
}
public void add(){
renderJsp("zdsadd.jsp");
}
public void addzds() throws Exception{
UploadFile file=getFile("file");
setAttr("file","upload/"+file.getFileName());
String wjm=file.getFile().getName().toString();
//String file_type=wjm.substring(wjm.lastIndexOf(".", wjm.length()));
String wordPath=PathKit.getWebRootPath()+"\\upload";
String wordName=wjm.substring(0,wjm.lastIndexOf("."));
String suffix=wjm.substring(wjm.lastIndexOf(".",wjm.length()));
//输入的word文件为:
String fileshuru = wordPath + File.separator + wordName + suffix;
System.out.println("原输入的word:"+fileshuru);
license = getClass().getClassLoader().getResourceAsStream("\\license.xml");// license路径
word=fileshuru; // 原始word路径
License aposeLic = new License();
aposeLic.setLicense(license);
long old = System.currentTimeMillis();
Document doc = new Document(word);
File file1 = new File(wordPath + File.separator + wordName + ".pdf"); // 输出路径
System.out.println("转换后输出的是什么:"+file1);
FileOutputStream fileOS = new FileOutputStream(file1);
doc.save(fileOS, SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒\n\n" + "文件保存在:" + file1.getPath());
fileOS.close();
}
}
评论0