这是我将myFile.pdf
文件打开到第 4 页的代码:
public static void main(String[] args) {
final String filePath = "myFile.pdf";
// build a component controller
SwingController controller = new SwingController();
PropertiesManager properties = new PropertiesManager(System.getProperties(),
ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
properties.setBoolean(PropertiesManager.PROPERTY_SHOW_UTILITY_PRINT, false);
SwingViewBuilder factory = new SwingViewBuilder(controller, properties);
JPanel viewerComponentPanel = factory.buildViewerPanel();
// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
new MyAnnotationCallback(controller.getDocumentViewController()));
//controller.getDocumentViewController().setDestinationTarget(controller.getDocument().getCatalog().getDestinations().);
JFrame applicationFrame = new JFrame();
applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
applicationFrame.setTitle("Test ICEPdf");
applicationFrame.getContentPane().add(viewerComponentPanel);
// Now that the GUI is all in place, we can try openning a PDF
controller.openDocument(filePath);
controller.showPage(3);
// show the component
applicationFrame.pack();
applicationFrame.setVisible(true); }
但是,我想在不使用的情况下导航到文档中showPage()
,例如使用 TOC 的锚点导航。因为如果我将内容添加到我的 PDF 文件中,我不想更改代码,因为页数会发生变化。
有解决办法吗?