[英]Java PDF Viewer
我正在使用 java 和 RCP,我試圖在我的視圖中使用 Acrobat 顯示 pdf 文檔。 我不需要改變它們。 這段代碼我有這個錯誤。 知道如何解決這個問題嗎? Ps:它同時運行良好。
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)
問候, 海瑟姆
看看這些免費的 pdf 渲染器...
一些鏈接...
http://www.icepdf.org/ (現在位於http://www.icesoft.org/java/projects/ICEpdf/overview.jsf - Apache 2 開源)
http://www.jpedal.org/support_siEclipse.php (現在在https://www.idrsolutions.com/jpedal/ - 商業)
https://java.net/projects/pdf-renderer (仍然可用https://github.com/yarick123/pdf-renderer - LGPL-2.1)
更新
ICEpdf 是一個開源 Java PDF 引擎,可以在任何 Java 應用程序或 Web 服務器上呈現、轉換或提取 PDF 內容。
對於基本功能,您必須在類路徑中包含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);
}
}
上面的代碼可幫助您在擺動組件上顯示 PDF。 你可以在 SWT 環境中做同樣的事情(看看SwingViewBuilder
.. 有點難,但會 SWT 的外觀和感覺)或使用org.eclipse.swt.awt.SWT_AWT
(有點簡單......但會有swing + swt 外觀和感覺)...雖然這兩種方法都可以解決您的目的。 還要檢查許可證文件夾中的適用許可證。
希望這會有所幫助。
這是另一個基於 Eclipse SWT 和 jPod Renderer 的免費、小巧且功能強大的 PDF 查看器 — JPview 。 它具有強大的渲染和低內存使用率。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.