开发手册 欢迎您!
软件开发者资料库

Java利用aspose组件将word转成pdf 中文乱码问题

之前工作有需求,要将word转成pdf,查找一些资料,试一些转档组件,最后发现aspose转档组件效果比较好。调用也比较简单,但是有些文件中文会有乱码,下面是我的调用代码。

        // / // / Word转成Pdf文件// / // / 源文件// / 转档文件public void WordConvertToPdf(String sourceFilePath, String pdfFilePath)throws Exception {try {                //验证licensecom.aspose.words.License lic = new com.aspose.words.License();lic.setLicense(Class.class.getResourceAsStream("license.xml"));com.aspose.words.Document doc = new com.aspose.words.Document(sourceFilePath);// validate parameterdoc.save(pdfFilePath, com.aspose.words.SaveFormat.PDF);} catch (com.aspose.words.IncorrectPasswordException ie) {throw new AsposeException("有密码!");} catch (com.aspose.words.UnsupportedFileFormatException ufe) {throw new AsposeException(String.format("文件格式无法识别! {0}",ufe.getMessage()));} catch (com.aspose.words.FileCorruptedException fce) {throw new AsposeException(String.format("文件损坏! {0}",fce.getMessage()));} catch (Exception ex) {throw ex;}}

做了许多尝试,也查了一些资料,最后发现在linux或windows系统中都有可能乱码,乱码原因都是操作系统中缺少word文件中的字体,在操作系统中安装该字体就可以了。