aspose页面文件预览问题

本文介绍了解决在Linux环境下预览PDF文件时出现中文乱码的问题,通过上传所需字体并配置字体路径解决。同时,针对文档大小、页数限制及预览时的评价模式提示,提供了设置License的方法。

问题:

预览pdf文件时,项目在windows上正常,在linux上中文乱码

解决:

将C:\Windows\Fonts下的字体(我需要的是宋体)上传到项目根目录/fonts上,并添加FontSettings.setFontsFolder(Word2PdfUtil.class.getResource("/").getPath()+"fonts", false);

代码如下:

import java.io.InputStream;
import java.io.OutputStream;

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

public class Word2PdfUtil {

	public static void doc2pdf(InputStream fileInputStream, OutputStream outputStream) {
		try {
			if (AsposeLicenseUtil.setWordsLicense()) {				FontSettings.setFontsFolder(Word2PdfUtil.class.getResource("/").getPath() + "fonts", false);
				Document doc = new Document(fileInputStream); // Address是将要被转化的word文档
				doc.save(outputStream, SaveFormat.PDF);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

参考:

https://apireference-qa.aspose.com/java/words/com.aspose.words/FontSettings

https://blog.csdn.net/qq_28800347/article/details/80895156

https://blog.csdn.net/qq_35617517/article/details/80879955

 

问题:

文档大小,页数有限制,且预览的文件上显示

This document was truncated here because it was created using Aspose.Words in Evaluation Mode.

解决:

设置license

/**
	 * 获取License的输入流
	 *
	 * @return
	 */
	private static InputStream getLicenseInput() {
		InputStream inputStream = null;
		ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
		try {
			inputStream = new FileInputStream(contextClassLoader.getResource("aspose"+File.separator+"license.xml").getPath());
		} catch (FileNotFoundException e) {
			logger.error("license not found!", e);
		}
		return inputStream;
	}

	/**
	 * 设置License
	 *
	 * @return true表示已成功设置License, false表示失败
	 */
	public static boolean setWordsLicense() {
		com.aspose.words.License aposeLic = new com.aspose.words.License();
		if (aposeLic.getIsLicensed()) {
			return aposeLic.getIsLicensed();
		}
		InputStream licenseInput = getLicenseInput();
		if (licenseInput != null) {
			try {
				aposeLic.setLicense(licenseInput);
				return aposeLic.getIsLicensed();
			} catch (Exception e) {
				logger.error("set words license error!", e);
			}
		}
		return false;
	}

参考:

https://www.cnblogs.com/zhangzhxb/p/5984766.html

https://blog.csdn.net/xiaosanshao9/article/details/51915952
 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值