我在使用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();
}
}