利用aspose-words直接將Word轉化爲圖片

以前遇到一個需求,須要在word文檔中加入一些文字,並轉化爲圖片。以前也試過幾種方案,可是發現效果還不是很理想,且中間須要通過一次轉化爲pdf的過程,最近找到了最理想的方式,即利用aspose-words做爲轉化工具,直接將word轉化爲圖片,無論是速度仍是質量都知足了咱們的需求java

具體實現

首先須要弄一個破解的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;
	}

}

最後是轉化的過程spa

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環境。你學會了嗎?.net

相關文章
相關標籤/搜索