Visualiseur PDF Java


J'utilise java et RCP et j'essaie d'afficher un document pdf avec Acrobat sur mes vues. Je n'ai pas besoin de les changer. J'ai cette erreur avec ce code. Une idée de comment résoudre ce problème?. P. s.: cela fonctionne bien en même temps.

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)

Cordialement, Haythem

Author: Boris Pavlović, 2010-12-14

2 answers

Jetez un oeil à ces rendus pdf gratuits ...

Quelques liens ...

  1. Http://www.icepdf.org/ (maintenant à http://www.icesoft.org/java/projects/ICEpdf/overview.jsf Je ne sais pas si c'est le cas.]}

  2. Http://www.jpedal.org/support_siEclipse.php (maintenant à https://www.idrsolutions.com/jpedal/ commercial)

  3. Https://java.net/projects/pdf-renderer (toujours disponible https://github.com/yarick123/pdf-renderer - LGPL-2.1)

Mise à JOUR

Par http://www.icepdf.org/ ,

ICEpdf est un PDF Java open source moteur qui peut rendre, convertir ou extraire le contenu PDF dans n'importe quel Java application ou sur un serveur Web.

Pour les fonctionnalités de base que vous devez inclure icepdf-core.jar et icepdf-viewer.jar dans votre chemin de classe. Selon l'exigence vous pouvez également ajouter le SVG soutien.

Extrait de l'exemple de dossier 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);
    }
}

Le code ci-dessus vous aide à afficher un PDF sur un composant swing. Vous pouvez faire la même chose dans l'environnement SWT (jetez un oeil à SwingViewBuilder .. un peu dur, mais sera SWT look and feel ) ou utiliser org.eclipse.swt.awt.SWT_AWT (un peu facile... mais aura swing + swt look and feel)... bien que les deux approches résoudront votre objectif. Vérifiez également les licences applicables dans le dossier licence.

J'espère que cela aidera.

 16
Author: Favonius, 2018-10-24 19:29:46

Voici une autre visionneuse PDF gratuite, petite et puissante basée sur Eclipse SWT et jPod Renderer - JPview . Il a un rendu fort et une faible utilisation de la mémoire.

 4
Author: user3417686, 2016-01-26 14:43:31