利用aspose-words直接将Word转化为图片

之前遇到一个需求,需要在word文档中加入一些文字,并转化为图片。之前也试过几种方案,但是发现效果还不是很理想,且中间需要经过一次转化为pdf的过程,最近找到了最理想的方式,即利用aspose-words作为转化工具,直接将word转化为图片,不管是速度还是质量都满足了我们的需求

具体实现

首先需要弄一个破解的license文件,以及jar包,那么这里提供下载地址 下面是读取license的工具类

import java.io.InputStream;

import com.aspose.words.License;
import com.zfsoft.serviceManagement.copy.controller.CopyController;

public class ReadConfigFile {

	public static boolean getLicense() {
		boolean result = false;
		try {
			InputStream is = CopyController.class.getClassLoader().getResourceAsStream("\\license.xml");
			License aposeLic = new License();
			aposeLic.setLicense(is);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
复制代码

最后是转化的过程

			File file = new File(pngPath);
			FileOutputStream os = new FileOutputStream(file);
			Document doc = new Document(wordDestPath);
			ImageSaveOptions iso = new ImageSaveOptions(SaveFormat.JPEG);
			iso.setResolution(200);
			doc.save(os, iso);
			// doc.save(os, SaveFormat.PNG);
			os.close();
复制代码

就是这么简单就能实现word转化为png的功能,且还不需要office环境。你学会了吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值