How to select pdf page using bookmark in pdf box?

前端 未结 1 543
离开以前
离开以前 2021-01-23 23:17

Sorry i am new to PDF box and was looking for a solution on how to get a specific pdf page using the bookmark name? Like the below code snippet am trying to loop all the pages b

1条回答
  •  孤街浪徒
    2021-01-23 23:58

    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();
        }
    }
    

    0 讨论(0)
提交回复
热议问题