Word转Pdf(无水印)

   需要得jar包和配置文件放在百度网盘上:

   链接:https://pan.baidu.com/s/1P_TXRKuOBAMYKGLvMIhYsQ 
   提取码:wdre 

   下载jar包后可将jar包放在maven私服上

package com.bee.supply.chain.finance.common.utils;

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

import org.apache.commons.io.IOUtils;
import org.aspectj.weaver.ast.Test;

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

/**
 * 
 * @Description word转pdf
 * @author 老板来个豆沙包
 * @Date 2019年4月17日
 * @version 1.0.0
 */
public class Word2PdfUtil {

	public static boolean getLicense() {
		boolean result = false;
		try {
			InputStream is = Test.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下
			License aposeLic = new License();
			aposeLic.setLicense(is);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static void doc2pdf(String tempWordFilePath, String tempPdfFilePath) {
		if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
			return;
		}
		FileOutputStream os = null;
		try {
			File file = new File(tempPdfFilePath);
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			os = new FileOutputStream(file);
			 
			//设置多个字体目录

			FontSettings.setFontsFolder("/usr/share/fonts/winFonts", false);

			Document doc = new Document(tempWordFilePath); // Address是将要被转化的word文档
			doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
											// EPUB, XPS, SWF 相互转换
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(os);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值