How to select pdf page using bookmark in pdf box?

淺唱寂寞╮ 提交于 2019-12-02 07:23:48

It turns out that in your PDF the page destination is not in the bookmark's destination entry, but in the bookmark's action entry (yes, PDF makes it possible to have two ways to do the same thing). Add this to your code:

if (current.getDestination() instanceof PDPageDestination)
{
    PDPageDestination pd = (PDPageDestination) current.getDestination();
    System.out.println("Destination page: " + (pd.retrievePageNumber() + 1));
    return pd.getPage();
}
if (current.getAction() instanceof PDActionGoTo)
{
    PDActionGoTo gta = (PDActionGoTo) current.getAction();
    if (gta.getDestination() instanceof PDPageDestination)
    {
        PDPageDestination pd = (PDPageDestination) gta.getDestination();
        System.out.println("Destination page: " + (pd.retrievePageNumber() + 1));
        return pd.getPage();
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!