【发布时间】:2010-12-08 10:37:30
【问题描述】:
我在使用 Sun 的 PDF Renderer 包查看带有嵌入字体的 PDF 时遇到问题。我有以下代码,它从 PDF 的每一页创建一个 BufferedImage 以在我的应用程序中查看,并且在没有嵌入字体时它工作正常。但是,当 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();
}
}
【问题讨论】: