spring 版本 word转png图片

license.xml创建粘贴即可

<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product><Product>Aspose.Cells for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>23dcc79f-44ec-4a23-be3a-03c1632404e9</SerialNumber></Data><Signature>2sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>
</License>

demo描述
本文包含word转png excel转png 由于excel转png顶部出现水印所以使用顶部裁剪的方式

package com.jeeplus.modules.api.util;import com.aspose.cells.*;
import com.aspose.words.*;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.utils.FileUtils;
import org.springframework.util.ResourceUtils;import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Iterator;/*** 封装文件 转 img*/
public class WordUrlUtil {/*** licence 验证** @return* @throws Exception*/public static boolean getLicenseWord() throws Exception {boolean result = false;try {File file = ResourceUtils.getFile("classpath:license.xml");InputStream is = new FileInputStream(file);com.aspose.words.License aposeLic = new com.aspose.words.License();aposeLic.setLicense(is);result = true;is.close();} catch (Exception e) {System.out.println("License 获取失败");e.printStackTrace();throw e;}return result;}/*** licence 验证** @return* @throws Exception*/public static boolean getLicenseExcel() throws Exception {boolean result = false;try {File file = ResourceUtils.getFile("classpath:license.xml");InputStream is = new FileInputStream(file);com.aspose.cells.License aposeLic = new com.aspose.cells.License();aposeLic.setLicense(is);result = true;is.close();} catch (Exception e) {System.out.println("License 获取失败");e.printStackTrace();throw e;}return result;}/*** word文档转图片* [url=home.php?mod=space&uid=952169]@Param[/url] inPath 传入文档地址* @param inPath 文件地址* @param outDir 输出图片文件夹* @return 返回文件地址,以逗号分割*/public static String doc2Img(String inPath, String outDir) {inPath = Global.getUserfilesBaseDir() + inPath;String address = outDir;outDir = Global.getUserfilesBaseDir() + outDir;FileUtils.createDirectory(outDir);String utls = "";try {if (!getLicenseWord()) {throw new Exception("com.aspose.words lic ERROR!");}System.out.println(inPath + " -> " + outDir);long old = System.currentTimeMillis();// word文档Document doc = new Document(inPath);// 支持RTF HTML,OpenDocument, PDF,EPUB, XPS转换ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);int pageCount = doc.getPageCount();for (int i = 0; i < pageCount; i++) {File file = new File(outDir + "/" + i + ".png");System.out.println(outDir + "/" + i + ".png");if (pageCount - 1 == i) {utls += address + i + ".png";} else {utls += address + i + ".png" + "|";}FileOutputStream os = new FileOutputStream(file);options.setPageIndex(i);doc.save(os, options);os.close();}long now = System.currentTimeMillis();System.out.println("convert OK! " + ((now - old) / 1000.0) + "秒");} catch (Exception e) {e.printStackTrace();}return utls;}
/**//*** excel 转 图片* @param inPath 文件地址* @param outDir 输出图片文件夹*/public static String excelImg(String inPath, String outDir) {inPath = Global.getUserfilesBaseDir() + inPath;String address = outDir;outDir = Global.getUserfilesBaseDir() + outDir;FileUtils.createDirectory(outDir);String utls = "";try {if (!getLicenseExcel()) {throw new Exception("com.aspose.words lic ERROR!");}System.out.println(inPath + " -> " + outDir);long old = System.currentTimeMillis();//使用aspose读取excelWorkbook book = new Workbook(inPath);//创建一个图表选项的对象ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();//设置图片类型imgOptions.setImageFormat(ImageFormat.getPng());imgOptions.setCellAutoFit(true);imgOptions.setOnePagePerSheet(true);//获取第一张工作表Worksheet sheet = book.getWorksheets().get(0);//创建一个纸张底色渲染对象SheetRender sr = new SheetRender(sheet, imgOptions);for (int j = 0; j < sr.getPageCount(); j++ ){//Generate an image for the worksheetsr.toImage(j, outDir +j+ ".png");utls+=address +j+ ".png";cutImage(outDir+j+ ".png",outDir+j+ ".png",0,16);//裁剪水印}long now = System.currentTimeMillis();System.out.println("convert OK! " + ((now - old) / 1000.0) + "秒");} catch (Exception e) {e.printStackTrace();}return utls;}/*** 图片裁剪通用接口** @param src  源图片地址,图片格式PNG* @param dest 目的图片地址* @param x    图片起始点x坐标* @param y    图片起始点y坐标* @throws IOException 异常处理*/public static void cutImage(String src, String dest, int x, int y)  {try{//获取png图片的ImageReader的IteratorIterator iterator = ImageIO.getImageReadersByFormatName("png");//根据Iterator获取ImageReaderImageReader reader = (ImageReader) iterator.next();//获取源图片输入流InputStream in = new FileInputStream(src);//根据源图片输入流获得ImageInputStream流ImageInputStream iis = ImageIO.createImageInputStream(in);//将ImageInputStream流加载到ImageReader中reader.setInput(iis, true);//图片读取参数ImageReadParam param = reader.getDefaultReadParam();Rectangle rect = new Rectangle(x, y, getImgWidth(new File(src)), getImgHeight(new File(src)));//参数对象设置形状为一定大小的长方形param.setSourceRegion(rect);//ImageReader根据参数对象获得BufferedImageBufferedImage bi = reader.read(0, param);//将经过参数对象筛选的图片流写入目标文件中ImageIO.write(bi, "png", new File(dest));}catch (IOException e){System.err.println("裁剪图片失败");}}/*** 获取图片宽度* @param file  图片文件* @return 宽度*/public static int getImgWidth(File file) {InputStream is = null;BufferedImage src = null;int ret = -1;try {is = new FileInputStream(file);src = javax.imageio.ImageIO.read(is);ret = src.getWidth(null); // 得到源图宽is.close();} catch (Exception e) {e.printStackTrace();}return ret;}/*** 获取图片高度* @param file  图片文件* @return 高度*/public static int getImgHeight(File file) {InputStream is = null;BufferedImage src = null;int ret = -1;try {is = new FileInputStream(file);src = javax.imageio.ImageIO.read(is);ret = src.getHeight(null); // 得到源图高is.close();} catch (Exception e) {e.printStackTrace();}return ret;}
}

maven

<!-- 这是excel的 -->
<dependency><groupId>com.aspose</groupId><artifactId>aspose-cells</artifactId><version>19.9</version></dependency>

word包jar包
https://pan.baidu.com/s/1Jp2UT4SaLXHYdK0GRPIQUQ

word转png图片 spring 版本相关推荐

  1. npoi2.0版本word中插入图片

     npoi2.0版本word中插入图片,也可以插入条码. namespace InsertPicturesInWord {     class Program     {         //ht ...

  2. FreeMaker+Xml导出word(含图片)

    最近在做一个简报导出的功能,要求导出word格式,上网找了很多资料,一开始选择了poi后来发现poi只能导出简单的word数据,后来偶然发现了通过FreeMaker模板生成word,说实话,还挺好用的 ...

  3. word 图片导入不翻转_如何在Microsoft Word中翻转图片

    word 图片导入不翻转 While Microsoft Word isn't known for its photo-editing abilities, it does have some bas ...

  4. java为word添加水印,图片水印和文字水印

    java为word添加水印,图片水印和文字水印 jdk1.5及以上 所需jar包:Spire.Office.jar 或 Spire.Doc.jar jar包下载:https://www.e-icebl ...

  5. 批量提取Word中的图片

    我在写学习笔记的时候喜欢用word或Evernote直接排版做笔记,好处是快速方便,直接截图插入.但是再刊载在CSND上的时候就有麻烦了,因为不能直接粘贴图片,只能上传到相册中再选取.这时我又不愿意一 ...

  6. C#技术分享【Word转换成图片和PDF——2种方案】

    上个工作完成之后,老大接着又布置一个任务,要求把Word转成图片,这次时间没有那么充裕,所以也没有研究的很深入,只跟大家分享2个很容易实现的方法. [Aspose.Words]第三方破解插件:其功能无 ...

  7. POI Word 模板 文字 图片 替换

    POI Word 模板 文字 图片 替换 博客分类: java poi POIjavaWOrd  实验环境:POI3.7+Word2007 Word模板: 替换后效果: 代码: 1.入口文件 Java ...

  8. POI生成word文档,图片显示为空白或不显示

    我想要用java,通过poi实现word文档中插入文字和图片来发送邮箱附件.但是发现在对word操作中,图片是白的,size如果设置小了直接没有图片.  经过百度 参考解决 Java poi 3.8 ...

  9. 经验:从ppt复制到word中的图片在导出成PDF后出现黑框怎么解决

    经验:从ppt复制到word中的图片在导出成PDF后出现黑框怎么解决 更新历史 20190602: 首次发布 在使用ppt和word的过程中,发现一个现象:将ppt中的图片复制到word中时,图片是没 ...

最新文章

  1. 【Android APT】注解处理器 ( 注解标注 与 初始化方法 )
  2. 机房收费系统=三层+设计模式
  3. 老司机教你将流量价值提升100倍
  4. 数控铣削图案及编程_数控铣削简单图案编程
  5. MySQL查询数据操作(DQL)
  6. 获取窗口上指定控件集合 2012-08-22 16:14 498人阅读 评论(0) 收藏...
  7. 团队第二次冲刺第三天
  8. 五款程序员专用辅助编程工具
  9. 为什么三表联查查出的数据每条出现好多次_独家解读!京东高可用分布式流数据存储的架构设计...
  10. 一键卡iPhoneQQ在线
  11. EPS学习笔记1----------常用快捷键
  12. 如何查看centos系统版本以及配置信息
  13. R TALK | 旷视研究院范浩强周舒畅: AI计算机摄影的原理、应用与硬件设计
  14. win7工作组看不到“其他电脑”的解决方法
  15. 华为p4不是鸿蒙吗怎么又改为安卓_鸿蒙系统是不是就是改版的安卓系统?
  16. 通过UEditor多图上传到七牛云出现图片不全,或上传失败bug
  17. 哪些场景N1 mode是disable状态
  18. 高通Camera驱动(2)-- openinitialize
  19. MySql计算两个日期的时间差函数
  20. 《TCP/IP卷》读书笔记

热门文章

  1. 跟着小程学微服务-Mock自动化系统的原理及实现
  2. TensorFlow最出色的30个机器学习数据集
  3. 市面精品 | 全套英语学习资源泄露,手慢则无!(禁止外传)
  4. Diablo3 的所失和所得
  5. 度盘视频视频网页倍速播放?一行代码就够了
  6. 【NodeJs-5天学习】第三天实战篇② ——基于物联网的WiFi自动打卡考勤系统
  7. VM安装Ubuntu后重启后报错“please remove the installation”?答案在这里
  8. Carson带你学设计模式:模板方法模式(Template Method)
  9. python调用matlab程序_Python调用MATLAB实现fmincon函数
  10. 数据与广告系列二十七:智能定向独特业务的独有炼丹配方