首页>代码>java转换excel为pdf文件>/AsposeCells/src/com/demo/Word2Pdf.java
package com.demo;


import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.words.Document; 
import com.aspose.words.SaveFormat;

/** 
 * @version 1.0 
 * 说明 :
 */
public class Word2Pdf {
	
	public static void main(String[] args) {

		String sourceFilePath="L:/testPDF/test.xls";//可生成PDF 没问题
		String desFilePath="L:\\testPDF\\PDF\\test.pdf";
		
		word2pdf(sourceFilePath, desFilePath);
		
	}
	
	
	public static boolean getLicense() {
		boolean result = false;
		try {
			InputStream is = Word2Pdf.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;
	}

	public static void word2pdf(String sourceFilePath,String desFilePath) {
		if (!getLicense()) { // 验证License 若不验证则转化出的PDP文档会有水印产生
			return;
		}
		try {
			
			File file = new File(desFilePath); // 新建一个空白pdf文档
			FileOutputStream os = new FileOutputStream(file);
			Document doc = new Document(sourceFilePath); // Address是将要被转化的word文档
			doc.save(os, SaveFormat.PDF); // 全面支持DOC, DOCX, OOXML, RTF HTML,
											// OpenDocument, PDF, EPUB, XPS, SWF
											// 相互转换 os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
13043860zj  LV16 2023年10月31日
ewan007  LV29 2023年6月19日
G你太美  LV9 2022年10月13日
8战魂5无双8  LV43 2022年9月13日
bnahlz  LV1 2022年3月2日
『周先生。』  LV1 2021年11月4日
Neoest  LV2 2021年7月15日
XuHuaHao  LV3 2021年6月28日
yinyuke  LV1 2021年6月15日
zhou0511  LV6 2021年6月1日
最近浏览更多
wsaffsa  LV2 2月19日
NHealers  LV5 2023年12月14日
13043860zj  LV16 2023年10月31日
chen影 2023年10月31日
暂无贡献等级
ewan007  LV29 2023年6月19日
zj0010722  LV2 2023年3月2日
ssy552  LV10 2023年2月23日
G你太美  LV9 2022年10月13日
jinnitom 2022年9月14日
暂无贡献等级
8战魂5无双8  LV43 2022年9月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友