6

I am using java and RCP and I am trying to show pdf Document with Acrobat on my views. I don't need to change them. I have this error with this code. Any idea how to resolve this problem?. P.s.: it works good same times.

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)

Regards, Haythem

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
Haythem
  • 417
  • 4
  • 13
  • 20

2 Answers2

16

Have a look at these free pdf renderer ...

Some links ...

  1. http://www.icepdf.org/ (now at http://www.icesoft.org/java/projects/ICEpdf/overview.jsf - Apache 2 Open Source)

  2. http://www.jpedal.org/support_siEclipse.php (now at https://www.idrsolutions.com/jpedal/ - commercial)

  3. https://java.net/projects/pdf-renderer (still available https://github.com/yarick123/pdf-renderer - LGPL-2.1)

UPDATE

As per http://www.icepdf.org/ ,

ICEpdf is an open source Java PDF engine that can render, convert, or extract PDF content within any Java application or on a Web server.

For basic functionality you have to include icepdf-core.jar and icepdf-viewer.jar in your class path. Depending upon the requirement you can also add the SVG support.

Taken from iceface sample folder:

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

The above code helps you in displaying a PDF on a swing component. You can do the same in the SWT environment (have a look at SwingViewBuilder .. kind of hard, but will SWT look and feel ) or use org.eclipse.swt.awt.SWT_AWT (kind of easy... but will have swing + swt look and feel)... though both approach will solve your purpose. Also check the applicable licenses in the license folder.

Hope this will help.

Pixelstix
  • 702
  • 6
  • 21
Favonius
  • 13,959
  • 3
  • 55
  • 95
  • Yes I saw them but I cann't found a way to open existing PDF files and to show them on a view. – Haythem Dec 14 '10 at 10:11
  • @Favonius: I am using org.nightlabs.eclipse.ui.pdfviewer – Haythem Dec 14 '10 at 10:16
  • @Haythem: As per nightlab page, they are internally using https://pdf-renderer.dev.java.net/ for rendering. Is there any image in the PDF file which is giving problem? The sun pdf-renderer is known to have problem with embedded tiff files. Have a look at this javalobby post http://www.javalobby.org/java/forums/t104502.html – Favonius Dec 14 '10 at 10:31
  • @Haythem: Also from the https://pdf-renderer.dev.java.net/ this was the only known release. I will suggest having a look at http://www.jpedal.org/support_siEclipse.php the reader source is also available on their page. – Favonius Dec 14 '10 at 10:36
  • @Favoonius: I should use an opensource project like iText. Do you have an example how to show an existing pdf document on a view with iText or an opensource? – Haythem Dec 14 '10 at 11:02
  • @Haythem: iText is a library to create, read or manipulate documents in the PDF format. You cannot use it for displaying/rendering pdf files. Although you can use icepdf. Check my updated answer. – Favonius Dec 14 '10 at 12:48
  • For any future comers - you can get the JARs directly off their old Google code project [here](https://code.google.com/p/tpt/source/browse/trunk/modules/tpt-core/lib/icepdf/?r=19). – smeeb Dec 22 '15 at 20:33
  • the point is, their font renderer engine is based on a license – madduci Sep 08 '17 at 08:20
4

Here is another free, small and powerful PDF Viewer based on Eclipse SWT and jPod Renderer — JPview. It has strong rendering and low memory usage.