Java 使用sun PDF渲染器显示带有嵌入式字体的PDF

Java 使用sun PDF渲染器显示带有嵌入式字体的PDF,java,pdf,Java,Pdf,我在使用Sun的PDF渲染器包查看带有嵌入式字体的PDF时遇到问题。我有下面的代码,它从PDF的每一页创建一个BuffereImage,以便在我的应用程序中查看,当没有嵌入字体时,它可以正常工作。但是,当PDF具有嵌入字体时,它不会显示文本。有什么想法吗?此外,它可以在Adobe的PDF查看器中正常打开 File f = new File("C:\\test.pdf"); FileChannel fc = new RandomAccessFile(f, "r").getChannel(); PD

我在使用Sun的PDF渲染器包查看带有嵌入式字体的PDF时遇到问题。我有下面的代码,它从PDF的每一页创建一个BuffereImage,以便在我的应用程序中查看,当没有嵌入字体时,它可以正常工作。但是,当PDF具有嵌入字体时,它不会显示文本。有什么想法吗?此外,它可以在Adobe的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();
    }
}
File f=新文件(“C:\\test.pdf”);
FileChannel fc=new RandomAccessFile(f,“r”).getChannel();
PDFFile PDFFile=新的PDFFile(fc.map(FileChannel.MapMode.READ_ONLY,0,fc.size());

对于(int x=0;x我通过将PDF渲染从PDFRenderer更改为PDFBox来解决这个问题,这会更好。更多信息可用。

您还可以查看提供开源PDF工具的Icesoft、IText、JPedal和Multivalent