2015-04-04 94 views
-1

我正在使用java製作PDF閱讀器,並且我想在我自己的應用程序的JFrame中打開PDF文件,以便我可以製作自己的功能。有沒有辦法做到這一點? 我使用「iText」,「pdfBox」和「ICEpdf」來操作PDF文檔。在JFrame中打開PDF

+0

對於PDFBox,獲取源代碼並查看PDFReader.java和PDFPagePanel.java。但我會說你的問題很廣泛,很可能會被標記出來。 – 2015-04-07 09:24:55

+0

您可以使用類PDPage類的方法'convertToImage',然後在JFrame上顯示圖像。 – cshu 2015-04-09 03:49:18

回答

2
public static void pdfViewerICE() { 
     String filePath = "PDF_URL"; 
     // build a controller 
     controller = new SwingController(); 

     // Build a SwingViewFactory configured with the controller 
     SwingViewBuilder factory = new SwingViewBuilder(controller); 
      PropertiesManager properties = new PropertiesManager(
       System.getProperties(), 
       ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE)); 

    properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75"); 

     // Use the factory to build a JPanel that is pre-configured 
     //with a complete, active Viewer UI. 
     JPanel viewerComponentPanel = factory.buildViewerPanel(); 

     controller.openDocument(filePath); 
     } 

上述代碼通過您的java程序使用ICEPDF打開PDF。 注意:在類路徑中包含ICEPDF jar(icepdf-viewer.jar,icepdf-core.jar)http://www.icesoft.org/java/downloads/icepdf-downloads.jsf