分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

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

发布时间:2023-09-06 02:27责任编辑:胡小海关键词: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环境。你学会了吗?

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

原文地址:https://www.cnblogs.com/zhendiao/p/10181966.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved