java 破解版 aspose-word 切图

网上找了好久的资料,发现aspose-word包可以用.支持 doc ,docx , et 可以转换PDF文档

官网API https://docs.aspose.com/display/wordsjava/Home

但是这个东西很耗内存,而且如果文档启用宏的话,进行切图会报错。这个没有处理。

还有切出来的每页图片内容跟源文档不一致,可能下一页的第一行到上一页的最后一行。

遇到某些文档报错,可能字体缺失,缺失哪种字体就下载放入 C:\Windows\Fonts 字体库


package wordCutImage;

import java.io.FileInputStream;
import java.io.InputStream;

import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;

public class Test {
	private static InputStream license;
	private static InputStream fileInput;

	/**
	 * 获取license
	 * 
	 * @return
	 */
	public static boolean getLicense() {
		boolean result = false;
		try {
			ClassLoader loader = Thread.currentThread().getContextClassLoader();

			license = new FileInputStream(loader.getResource("license.xml").getPath());// 凭证文件

			fileInput = new FileInputStream(loader.getResource("test.doc").getPath()); // 文件路径

			com.aspose.words.License license1 = new com.aspose.words.License();

			license1.setLicense(license);

			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static void main(String[] args) throws Exception {
		if (!getLicense()) {
			return;
		}

		try {
			long old = System.currentTimeMillis();
			
			Document pdfDocument = new Document(fileInput);

			ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);

			options.setPrettyFormat(true);

			options.setUseAntiAliasing(true);

			options.setUseHighQualityRendering(true);

			for (int i = 0; i < pdfDocument.getPageCount(); i++) {

				String fileName = "第" + i + "张.jpg";

				options.setPageIndex(i);

				System.out.println(i);

				pdfDocument.save("D:/wordTest/" + fileName, options);
			}

			long now = System.currentTimeMillis();
			System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒 ");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

程序下载链接 https://download.csdn.net/download/hqbootstrap1/10491476




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值