Aspose.pdf.java转换问题

用aspose.pdf.java把pdf转换成图片,会有部分转换出现错误,具体请查看附件,请问是什么原因呢?需转换图片文件.pdf (134.2 KB)
转换之后的图片.jpg (4.7 KB)

@changmi

感谢您与我们联系。

我们已经使用Aspose.PDF for Java 18.6和以下代码片段在我们的环境中测试了场景。

Document pdfDocument = new  Document(dataDir + "需转换图片文件.pdf");
com.aspose.pdf.RenderingOptions ro = new com.aspose.pdf.RenderingOptions();
ro.setUseFontHinting(true);
for (int pageCount = 1; pageCount <= pdfDocument.getPages().size(); pageCount++)
{
 java.io.OutputStream imageStream = new java.io.FileOutputStream(dataDir + "Converted_Image" + pageCount + ".jpg");
 com.aspose.pdf.devices.Resolution resolution = new  com.aspose.pdf.devices.Resolution(120);
 // Create JpegDevice object where second argument indicates the quality of resultant image
 com.aspose.pdf.devices.JpegDevice jpegDevice = new  com.aspose.pdf.devices.JpegDevice(664, 484, resolution, 90);
 jpegDevice.setRenderingOptions(ro);
 jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
 imageStream.close();

我们在输出图像文件中注意到了这个问题,为了更正,我们在问题跟踪系统中将其记录为PDFJAVA-37851。我们将进一步调查此问题,并随时向您通报其解决方案的状态。请耐心等待我们。

对此造成的不便,我们表示歉意。

@changmi

谢谢你的耐心。

我们调查了早期记录的问题,并在Aspose.PDF for Java 18.7中得到了解决。

请注意,他的字体FZXBSJW - GB1-0(方正小标宋简体)未嵌入PDF文件中,并且在默认字体目录中不存在。因此,对于成功转换,此字体应该存在,或者可以通过下面的代码替换为其他字体:

try{
Document pdfDocument = new  Document(dataDir + "需转换图片文件.pdf");
FontRepository.getSubstitutions().add(new PDFJAVA_37851Substitution());
...

private static class PDFJAVA_37851Substitution extends CustomFontSubstitutionBase {
   @Override
   public boolean trySubstitute(CustomFontSubstitutionBase.OriginalFontSpecification originalFontSpecification, com.aspose.pdf.Font[] substitutionFont) {
        if (originalFontSpecification.getOriginalFontName().startsWith("FZXBSJW--GB1-0")) {
                 substitutionFont[0]  = FontRepository.findFont("Arial Unicode MS");
                // or substitutionFont[0] = FontRepository.findFont("Droid Sans Fallback");
                // or substitutionFont[0] = FontRepository.findFont("SimSun");

                return true;
            } else {
                return false;
            }
        }
    }

我们使用Arial Unicode MS,Droid Sans Fallback和SimSun字体获得了良好的效果,但您也可以尝试使用其他字体