用aspose实现word与excel转成pdf的功能,附件是myeclipse工程,导入即可运行,生成的pdf文件在与源word或excel文件相同目录下,无水印,无文件大小限制。
资源下载地址: http://download.csdn.net/detail/lihong22/9700174
package pdf;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Locale;
import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import com.aspose.words.Document;
public class ExeclAndWordToPdf
{
/**
* 支持DOC, DOCX, OOXML, RTF, HTML, OpenDocument, PDF, EPUB, XPS, SWF等相互转<br>
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String fileName = "";
/*String filePath = "C:\\Users\\Ai\\Desktop\\临时文件\\外包任务推送操作手册.docx";
String filePathWord = wordToPdf(filePath,fileName);
System.out.println("word生成pdf文件的路径:"+filePathWord);*/
String filePath = "C:\\Users\\Ai\\Desktop\\临时文件\\工作簿1.xlsx";
String filePathExcel = excelToPdf(filePath,fileName);
System.out.println("excel生成pdf文件的路径:"+filePathExcel);
}
/**
* Excel生成PDF文件
*
* @param filePath
* @throws Exception
*/
public static String excelToPdf(String filePath,String fileName) throws Exception {
// 验证License
if (!getExcelLicense()) {
return "Excel license fault!";
}
String filePathBorf = filePath.substring(0, filePath.lastIndexOf("\\")+1);
if ("".equals(fileName)) {
fileName = filePath.substring(filePath.lastIndexOf("\\")+1, filePath.indexOf("."));
}
long old = System.currentTimeMillis();
Workbook wb = new Workbook(filePath);// 原始excel路径
String filePathTemp = filePathBorf + fileName+ ".pdf";
File pdfFile = new File(filePathTemp);// 输出路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
wb.save(fileOS, SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时" + ((now - old) / 1000.0) + "秒");
return filePathTemp;
}
/**
* word生成PDF文件
*
* @param filePath
* @throws Exception
*/
public static String wordToPdf(String filePath,String fileName) throws Exception {
// 验证License
if (!getWordLicense()) {
return "Word license fault!";
}
long old = System.currentTimeMillis();
// 打开文档实例
Document doc = new Document(filePath);
String filePathBorf = filePath.substring(0, filePath.lastIndexOf("\\")+1);
if ("".equals(fileName)) {
fileName = filePath.substring(filePath.lastIndexOf("\\")+1, filePath.indexOf("."));
}
String filePathTemp = filePathBorf + fileName+ ".pdf";
doc.save(filePathTemp, com.aspose.words.SaveFormat.PDF);
long now = System.currentTimeMillis();
System.out.println("共耗时" + ((now - old) / 1000.0) + "秒");
return filePathTemp;
}
/**
* 获取license
*
* @return
*/
public static boolean getExcelLicense() {
boolean result = false;
try {
InputStream is = ExeclAndWordToPdf.class.getClassLoader().getResourceAsStream("\\license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 获取license
*
* @return
*/
public static boolean getWordLicense() {
boolean result = false;
try {
InputStream is = ExeclAndWordToPdf.class.getClassLoader().getResourceAsStream("\\license.xml");
com.aspose.words.License aposeLic = new com.aspose.words.License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
相关推荐
winForm word转pdf excel转pdf winForm word转pdf excel转pdf winForm word转pdf excel转pdf winForm word转pdf excel转pdf
实现word excel ppt转为pdf,并提供转格式后删除原来的文件。(需要使用jcom)
poi将word、PPT、Excel转pdf实现在线预览的jar包
办公自动化python将Word、Excel和PPT批量转成PDF文档,win32com操作word文档、Excel表格和PPT文档,WPS转为PDF文件。提高办公效率,快速阅读office文件,保护office文件格式和文件安全。
Jacob Word excel 转PDF 合并PDF文件,需要安装微软的转换插件,压缩包内含插件
word、excel、ppt转pdf小demo,毫无水印,全套可用包含三个jar,三个测试文档,还有可用license.xml,spring boot写的,建议idea打开
word转换pdf、excel转换pdf、jpeg转换pdf等的工具PDF转换器注册码
aspose 实现 word excel ppt 转pdf,实现文件预览功能。
Word/Excel/PPT2007转PDF插件
java OpenOffice wordExcel转换PDF.zip 带jar包
前端实现文件预览(word、excel、pdf、ppt、mp4、图片、文本)
java实现在线预览,将word,excel转换成html
aspose.cell,aspose.word,15.8.0版本license.xml,亲测转pdf无水印,无时间限制,警告:请勿用于商业用途,仅供学习研究,如有任何版权纠纷,本人概不负责!
支持各种复杂样式的office文档转pdf、html实现;实例提供了核心实现方法以及相关依赖包,有问题可以留言交流;
C# 调用office2010组件,将EXCEL转PDF和word转PDF,其中解决了excel文档列过多的问题,需要安装office2010。。
word,excel 转pdf 生成的pdf和选取的word,excel在同一个目录
实现word、excel、PPT 转PDF文件功能。去插件水印,添加word、excel、pdf 文字与图片水印功能。执行转化方法前会分别先执行loadLicense()、getLicenseExcel()、getLicensePpt() 加载license.xml文件,不会出现插件...
Winform 轻松实现Word/Excel转换为PDF文件
word转pdf excel转pdf ppt转pdf pdf转word pdf转excel pdf转ppt pdf转html pdf转svg 等等