java 破解版 aspose-word 切图

编程知识 行业动态 更新时间:2024-06-13 00:21:19

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

官网API https://docs.aspose/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/download/hqbootstrap1/10491476




更多推荐

java 破解版 aspose-word 切图

本文发布于:2023-03-31 15:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/dccd8743701d7b576776db6eba357917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:破解版   java   aspose   切图   word

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!