2014-11-06 25 views

回答

2

您可以考慮使用ICEPDF,它可以在OpenSource版和專業版中使用。下面的示例顯示瞭如何在JPanel中顯示PDF:

String filePath = "somefilepath/myfile.pdf"; 

// build a controller 
SwingController controller = new SwingController(); 

// Build a SwingViewFactory configured with the controller 
SwingViewBuilder factory = new SwingViewBuilder(controller); 

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

// add copy keyboard command 
ComponentKeyBinding.install(controller, viewerComponentPanel); 

// add interactive mouse link annotation support via callback 
controller.getDocumentViewController().setAnnotationCallback(
     new org.icepdf.ri.common.MyAnnotationCallback(
      controller.getDocumentViewController())); 

// Create a JFrame to display the panel in 
JFrame window = new JFrame("Using the Viewer Component"); 
window.getContentPane().add(viewerComponentPanel); 
window.pack(); 
window.setVisible(true); 

// Open a PDF document to view 
controller.openDocument(filePath); 
+0

謝謝,我現在查過了,太棒了!正是我需要的! – user2824073 2014-11-06 19:01:43