zoukankan      html  css  js  c++  java
  • 利用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环境。你学会了吗?

  • 相关阅读:
    事以密成,能者低调
    时间过得真快,一晃三年过去了
    读书随记2011111
    Makefile
    ubuntu 7 下 tftp 的配置
    uboot移植到nano2410
    ubuntu 7.04 Feisty Fawn 安装手记之五:安装常用软件
    移植linux2.6.18到arm9
    移植busybox 1.4.2
    UBoot中SMDK2410的NAND Flash驱动。
  • 原文地址:https://www.cnblogs.com/zhendiao/p/10181966.html
Copyright © 2011-2022 走看看