无需页面编号即可使用ICEpdf导航到PDF文档

时间:2018-10-19 08:08:10

标签: java pdf icepdf

这是我的代码,用于打开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文件时更改代码,因为页数会发生变化。

有解决方案吗?

0 个答案:

没有答案