Linux设置Windows字体

1.为什么在Linux设置Windows字体

  • 在word转pdf时,在Windows上不乱码,在Linux上乱码,因此需在Linux上设置Windows字体。
import com.aspose.words.Document;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class Doc2PdfUtil {

	/**
	 * 获取许可码
	 *
	 * @return
	 */
	public static boolean getLicense() {
		try {
			InputStream is = Doc2PdfUtil.class.getClassLoader().getResourceAsStream("license.xml");
			License aposeLic = new License();
			aposeLic.setLicense(is);
			return Boolean.TRUE;
		} catch (Exception e) {
			e.printStackTrace();
		}

		return Boolean.FALSE;
	}

	/**
	 * doc转pdf
	 * 
	 * @param sourcePath
	 * @param targetPath
	 */
	public static void doc2pdf(String sourcePath, String targetPath) {
		getLicense();
		try {
			File file = new File(targetPath); // 新建一个空白pdf文档
			FileOutputStream os = new FileOutputStream(file);
			Document doc = new Document(sourcePath); // Address是将要被转化的word文档
			doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
		} catch (Exception e) {
			throw new RuntimeException("Word转PDF错误。", e);
		}
	}

}
复制代码
  1. 在Linux上设置Windows字体
  • 将Windows C:\Windows\Fonts路径下的字体(后缀为ttc,ttf)拷贝到Linux路径下的/usr/share/fonts/windows(若无此路径则建立)

  • 修改字体文件权限

    cd /usr/share/fonts/windows

    chmod 755 *.ttf

    chmod 755 *.ttc

  • 建立字体缓存

    mkfontscale (如果提示 mkfontscale: command not found,需自行安装 # yum install mkfontscale )

    mkfontdir

    fc-cache -fv (如果提示 fc-cache: command not found,则需要安装# yum install fontconfig )

  • 字体生效

    source /etc/profile

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享