2009-10-20 94 views
0

我在使用Sun的PDF渲染器程序包查看嵌入字體的PDF時遇到問題。我有下面的代碼創建一個PDF的每個頁面BufferedImage用於在我的應用程序中查看,並且它沒有嵌入字體時工作正常。但是,當PDF嵌入字體時,它不顯示任何文本。有任何想法嗎?此外,它可以在Adobe的PDF查看器中打開。使用sun PDF渲染器顯示嵌入字體的PDF

File f = new File("C:\\test.pdf"); 
FileChannel fc = new RandomAccessFile(f, "r").getChannel(); 
PDFFile pdfFile = new PDFFile(fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size())); 
for(int x=0; x<pdfFile.getNumPages(); x++) { 
    try { 
     BufferedImage bi = (BufferedImage)pdfFile.getPage(x+1).getImage(
      (int)pdfFile.getPage(x+1).getWidth(), 
      (int)pdfFile.getPage(x+1).getHeight(), 
      new Rectangle((int)pdfFile.getPage(x+1).getWidth(), 
      (int)pdfFile.getPage(x+1).getHeight()), 
      null, true, true); 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

回答

1

我想通過將PDF渲染器從PDFRenderer更改爲PDFBox來實現這一點,該工具效果更好。有更多的信息here

1

您還可以查看提供開源PDF工具的Icesoft,IText,JPedal和Multivalent。