2017-02-28 59 views
0

我已经进口PDFBOX-2.0.4.jarfontbox-2.0.4.jar共享记录-1.1.1.jar到Eclipse开普勒。该程序运行在win10上。 控制台打印大量此类警告pdfbox2.0.4将PDF转换与中国为PNG

org.apache.pdfbox.pdmodel.font.PDCIDFontType2 <init> 
WARNING: Using fallback font ArialUnicodeMS for CID-keyed TrueType font KaiTi_GB2312. 

我不能访问与整个内容的图像文件。我该如何解决它? 我的代码是这样的:

public class PdfboxTest { 
    private static final String filePath = "xxx"; 
    private static final String outputFilePath = "xxx"; 

    public static void change(File inputFile, File outputFolder) throws IOException { 

     String totalFileName = inputFile.getName(); 
     String fileName = totalFileName.substring(0,totalFileName.lastIndexOf(".")); 
     PDDocument doc = null; 
     try { 
      doc = PDDocument.load(inputFile); 
      PDFRenderer pdfRenderer = new PDFRenderer(doc); 
      int pageCounter = 0; 
      for(PDPage page : doc.getPages()) 
      { 
       BufferedImage bim = pdfRenderer.renderImageWithDPI(pageCounter, 300, ImageType.RGB); 
       ImageIOUtil.writeImage(bim, outputFilePath + "\\" + fileName + (pageCounter++) +".png", 300); 
      } 
      doc.close(); 

     } finally { 
      if (doc != null) { 
       doc.close(); 
      } 
     } 
    } 
    public static void main(String[] args) { 
     File inputFile = new File(filePath); 
     File outputFolder = new File(outputFilePath); 
     if(!outputFolder.exists()){ 
      outputFolder.mkdirs(); 
     } 
     try { 
      change(inputFile, outputFolder); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

    } 
} 
+1

尝试安装缺少的字体,例如'KaiTi_GB2312',这是来自没有嵌入字体的PDF文件。 Re'我无法访问整个内容的图像文件'你是什么意思,这是一个权限问题,还是你的意思是图像中缺少中文文本? –

+0

感谢您的编辑建议和问题建议。我通过安装字体KaiTi_GB2312解决了这个问题。现在我可以通过pdf获得整个内容的图像。 – dragic

回答

0

正如在评论中看到的 - 最好的解决办法是安装缺少的字体KaiTi_GB2312。信息Using fallback font意味着PDF引用了所提到的字体,并未嵌入它,但无法在您的计算机上找到它,所以PDFBox尝试了一种备用解决方案,在这种情况下为ArialUnicodeMS字体。令人遗憾的是,这种后备解决方案并不总是完美的,这就是为什么渲染图像中有些字形丢失的原因。