使用sun PDF Renderer显示带有嵌入字体的PDF [英] Using sun PDF Renderer to display PDFs with embedded fonts

查看:242
本文介绍了使用sun PDF Renderer显示带有嵌入字体的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Sun的PDF Renderer软件包查看带有嵌入式字体的PDF时遇到麻烦.我有以下代码,可以从PDF的每一页中创建一个BufferedImage以便在我的应用程序中查看,并且在没有嵌入式字体时可以正常工作.但是,当PDF嵌入字体时,它不会显示任何文本.有任何想法吗?此外,它可以在Adobe的PDF查看器中很好地打开.

I'm having trouble using Sun's PDF Renderer package to view PDFs with embedded fonts. I have the following code which creates a BufferedImage out of every page of a PDF for viewing in my application, and it works fine when there are no embedded fonts. However, when the PDF has embedded fonts, it shows no text. Any ideas? Also, it opens fine in Adobe's PDF viewer.

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();
    }
}

推荐答案

我通过将PDF渲染器从PDFRenderer更改为PDFBox来解决这个问题,效果更好. 此处.

I figured this out by changing PDF renders from PDFRenderer to PDFBox, which works much better. More info is available here.

这篇关于使用sun PDF Renderer显示带有嵌入字体的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆