Java PDF查看器

Java PDF查看器,java,pdf,rcp,pdfrenderer,Java,Pdf,Rcp,Pdfrenderer,我正在使用java和RCP,并试图在视图中使用Acrobat显示pdf文档。 我不需要改变它们。 我的代码有这个错误。你知道怎么解决这个问题吗?。附言:它在同一时间也很有效 PDFFile pdfFile; pdfFile = PdfFileLoader.loadPdf(file, new NullProgressMonitor()); PdfDocument pdfDocument = new OneDimensionalPdfDocument(pdfFile, new NullProgres

我正在使用java和RCP,并试图在视图中使用Acrobat显示pdf文档。 我不需要改变它们。 我的代码有这个错误。你知道怎么解决这个问题吗?。附言:它在同一时间也很有效

PDFFile pdfFile;
pdfFile = PdfFileLoader.loadPdf(file, new NullProgressMonitor());
PdfDocument pdfDocument = new OneDimensionalPdfDocument(pdfFile, new NullProgressMonitor());
pdfViewer.setPdfDocument(pdfDocument);

Error from PdfDocument pdfDocument = new OneDimensionalPdfDocument(pdfFile, new NullProgressMonitor()) : Unsupport CMap format: 6
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Unknown Source)
at java.nio.HeapByteBuffer.getShort(Unknown Source)
at com.sun.pdfview.font.ttf.HmtxTable.setData(HmtxTable.java:79)
at com.sun.pdfview.font.ttf.TrueTypeTable.createTable(TrueTypeTable.java:113)
at com.sun.pdfview.font.ttf.TrueTypeFont.getTable(TrueTypeFont.java:106)
at com.sun.pdfview.font.TTFFont.getOutline(TTFFont.java:129)
at com.sun.pdfview.font.TTFFont.getOutline(TTFFont.java:89)
at com.sun.pdfview.font.OutlineFont.getGlyph(OutlineFont.java:118)
at com.sun.pdfview.font.PDFFont.getCachedGlyph(PDFFont.java:307)
at com.sun.pdfview.font.PDFFontEncoding.getGlyphFromEncoding(PDFFontEncoding.java:132)
at com.sun.pdfview.font.PDFFontEncoding.getGlyphs(PDFFontEncoding.java:98)
at com.sun.pdfview.font.PDFFont.getGlyphs(PDFFont.java:273)
at com.sun.pdfview.PDFTextFormat.doText(PDFTextFormat.java:283)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:742)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:88)
at java.lang.Thread.run(Unknown Source)
问候,,
Haytem

看看这些免费的pdf渲染器

一些链接

  • (现在位于-Apache2开源)

  • (现为商业版)

  • (仍然可用-LGPL-2.1)

  • 更新

    根据,

    ICEpdf是一种开源Java PDF 可以渲染、转换或删除的引擎 在任何Java中提取PDF内容 应用程序或Web服务器上的

    对于基本功能,您必须在类路径中包含
    icepdf core.jar
    icepdf viewer.jar
    。根据需要,还可以添加SVG支持

    取自iceface示例文件夹:

    import org.icepdf.ri.common.SwingController;
    import org.icepdf.ri.common.SwingViewBuilder;
    
    import javax.swing.*;
    
    /**
     * The <code>ViewerComponentExample</code> class is an example of how to use
     * <code>SwingController</code> and <code>SwingViewBuilder</code>
     * to build a PDF viewer component.  A file specified at the command line is
     * opened in a JFrame which contains the viewer component.
     *
     * @since 2.0
     */
    public class ViewerComponentExample {
        public static void main(String[] args) {
            // Get a file from the command line to open
            String filePath = args[0];
    
            // build a component controller
            SwingController controller = new SwingController();
    
            SwingViewBuilder factory = new SwingViewBuilder(controller);
    
            JPanel viewerComponentPanel = factory.buildViewerPanel();
    
            // add interactive mouse link annotation support via callback
            controller.getDocumentViewController().setAnnotationCallback(
                    new org.icepdf.ri.common.MyAnnotationCallback(
                            controller.getDocumentViewController()));
    
            JFrame applicationFrame = new JFrame();
            applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            applicationFrame.getContentPane().add(viewerComponentPanel);
    
            // Now that the GUI is all in place, we can try openning a PDF
            controller.openDocument(filePath);
    
            // show the component
            applicationFrame.pack();
            applicationFrame.setVisible(true);
        }
    }
    
    上面的代码帮助您在swing组件上显示PDF。您可以在SWT环境中执行同样的操作(查看一下
    SwingViewBuilder
    。有点难,但是会使用SWT外观),或者使用
    org.eclipse.SWT.awt.SWT\u awt
    (有点简单……但是会有swing+SWT外观)。。。尽管这两种方法都能解决你的问题。还要检查许可证文件夹中的适用许可证


    希望这会有所帮助。

    这里是另一个基于Eclipse SWT和jPod渲染器的免费、小型且功能强大的PDF查看器-。它具有很强的渲染能力和较低的内存使用率。

    您使用的是哪个库?是的,我看到了它们,但我找不到打开现有PDF文件并在视图上显示它们的方法。@Favonius:我使用的是org.nightlabs.eclipse.ui。pdfviewer@Haythem:根据nightlab页面,它们在内部用于渲染。PDF文件中是否有任何图像出现问题?众所周知,sun pdf渲染器存在嵌入tiff文件的问题。看看这个javalobby帖子@Haythem:也是从上个月开始的,这是唯一已知的版本。我建议您在他们的页面上查看一下阅读器的源代码。@Favoonius:我应该使用像iText这样的开源项目。您是否有一个示例,说明如何使用iText或开源在视图上显示现有的pdf文档?