利用aspose doc转成pdf在linux下汉字出现小方框

 在方法中加上设置字体的的存放路径,我在代码中写死了。

前提/usr/share/fonts已安装windows下的字体。参考

https://blog.csdn.net/GZSGZSgg/article/details/95641217

再参考https://blog.csdn.net/qq_35617517/article/details/80879955

解决乱码问题。

File file = new File(pdfPath); //新建一个pdf文档
FileOutputStream os = new FileOutputStream(file);
System.out.println("操作系统名称:" + System.getProperty("os.name")); // 操作系统名称
FontSettings.setFontsFolder("/usr/share/fonts" + File.separator, true);//此处处理乱码和小方块
Document doc = new Document(wordPath); //Address是将要被转化的word文档
doc.save(os, com.aspose.words.SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换

利用aspose doc转成pdf在linux下汉字出现小方框_第1张图片 

利用aspose doc转成pdf在linux下汉字出现小方框_第2张图片

你可能感兴趣的:(java)