You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Mustafa Farooqui <mu...@gmail.com> on 2017/07/14 14:55:57 UTC

Iterate and access the pages under sub bookmark

Hi,

I am trying to access the pages which are under the sub bookmark .
Below is the structure of the pdf file and under it there sub
bookmarks. These sub bookmarks have multiple pages which are basically
forms extended to more than one page. I am able to get to those sub
bookmark. However, cannot iterate over those pages or get any specific
page i need to edit or resize?

Can anyone please suggest or help? I can share the code but cannot
share the confidential pdf which I am working on. I tried  finding the
sample document online but couldn't find any.  My question is similar
to the below link which i found on stackover flow.

https://stackoverflow.com/questions/45002625/how-to-load-the-pages-which-are-under-the-sub-bookmark-using-pdf-box


Below is the structure of my PDF document

MainBookMarkName|_firstBookMark (1-10 pages)
 -page1
 -page2
 -page3
 -page4
 - .
 - .
 -page10|_secondBookMark (1-5 pages)
 -page1
 -page2
 -page3
 -page4
 -page5|_thirdBookMark (1-8 pages)
 -page1
 -page2
 -page3
 - .
 - .
 -page8|_FourthBookMark|_|_|_lastBookMark


Thanks

Mustafa

Re: Iterate and access the pages under sub bookmark

Posted by Gilad Denneboom <gi...@gmail.com>.
A bookmark doesn't point to a range of pages. It *can *point to a single
page, and then the next one points to another page, etc.
The range between those two bookmarks is imaginary, as the second bookmark
can do something else entirely (like open a web-page), or point to a page
before the previous bookmark, or do nothing at all...
So what you need to do is get the next sibling (which you are doing), and
then check what it does. If it indeed points to a page number, and that
number is greater than (or equal to) the page number pointed to by the
current bookmark then you have your "range" and you can do with it as you
wish.
You also need to decide how to handle the last bookmark. Is the "range"
it's pointing to a single page? Or is it that page until the end of the
file? etc.

On Fri, Jul 14, 2017 at 9:48 PM, Mustafa Farooqui <mustafafarooqui@gmail.com
> wrote:

> Adding to my previous email this is the basic structure
>
> *PDF -> MainBookMark -> subBookMark1 -> pages( 1- 10 etc..)*
>
>
>
>
> On Fri, Jul 14, 2017 at 2:33 PM, Mustafa Farooqui <
> mustafafarooqui@gmail.com
> > wrote:
>
> > Below is my code and pdf structure which am working on. I am stuck at a
> > point where i am trying to get the pages which are under the
> "subBookMark1".
> > These pages are basically forms which are more than one pages. I am not
> > sure how to iterate over these pages under subBookMark1. Like page 1,
> page2
> > , page 3 etc.  Hope this information helps you to understand my issue?
> >
> >
> > Below is my PDF structure
> >
> > *MainBookMarkName
> > |_subBookMark1 (1-10 pages)
> >  -page1
> >  -page2
> >  -page3
> >  -page4
> >  - .
> >  - .
> >  -page10
> > |_**subBookMark2** (1-5 pages)*
> > * -page1
> >  -page2
> >  -page3
> >  -page4
> >  -page5
> > |_**subBookMark3 ** (1-8 pages)*
> > * -page1
> >  -page2
> >  -page3
> >  - .
> >  - .
> >  -page8
> > |_**subBookMark4*
> > *
> > |_
> > |_
> > |_**subBookMark5*
> >
> > My Code
> >
> > public static PDPage printBookmark(PDDocument document, PDOutlineNode
> > node, String indentation)
> > throws IOException {
> > PDOutlineItem mainBookMark= node.getFirstChild();
> > PDOutlineItem subBookMark1= mainBookMark.getFirstChild();
> >
> > while (subBookMark1!= null) {
> > System.out.println(subBookMark1.getTitle());
> >
> > if (subBookMark1.getDestination() instanceof PDPageDestination) {
> >
> > if (subBookMark1.getTitle().equals("subBookMark1 Title")) {
> >
> >
> > PDPageDestination pd = (PDPageDestination) subBookMark1.getDestination();
> >
> > System.out.println("Destination page: " + (pd.retrievePageNumber() +
> 1));
> >
> > return pd.getPage();
> >
> > }
> > }
> > printBookmark(document, subBookMark1, indentation + "    ");
> > subBookMark1= subBookMark1.getNextSibling();
> > }
> > return null;
> >
> > }
> >
> >
> >
> > On Fri, Jul 14, 2017 at 11:10 AM, Gilad Denneboom <
> > gilad.denneboom@gmail.com> wrote:
> >
> >> What exactly is the issue? Do you know how to access the Outline root?
> Do
> >> you know how to proceed from there to the children/siblings (this will
> >> require a recursive function, unless you know there is only a fixed
> amount
> >> of levels in the bookmark hierarchy)? Do you know how to access the
> >> action(s) associated with each bookmark?
> >> It would be helpful if you could let us know to which point you've
> >> arrived,
> >> and where you got stuck...
> >>
> >> On Fri, Jul 14, 2017 at 4:55 PM, Mustafa Farooqui <
> >> mustafafarooqui@gmail.com
> >> > wrote:
> >>
> >> > Hi,
> >> >
> >> > I am trying to access the pages which are under the sub bookmark .
> >> > Below is the structure of the pdf file and under it there sub
> >> > bookmarks. These sub bookmarks have multiple pages which are basically
> >> > forms extended to more than one page. I am able to get to those sub
> >> > bookmark. However, cannot iterate over those pages or get any specific
> >> > page i need to edit or resize?
> >> >
> >> > Can anyone please suggest or help? I can share the code but cannot
> >> > share the confidential pdf which I am working on. I tried  finding the
> >> > sample document online but couldn't find any.  My question is similar
> >> > to the below link which i found on stackover flow.
> >> >
> >> > https://stackoverflow.com/questions/45002625/how-to-
> >> > load-the-pages-which-are-under-the-sub-bookmark-using-pdf-box
> >> >
> >> >
> >> > Below is the structure of my PDF document
> >> >
> >> > MainBookMarkName|_firstBookMark (1-10 pages)
> >> >  -page1
> >> >  -page2
> >> >  -page3
> >> >  -page4
> >> >  - .
> >> >  - .
> >> >  -page10|_secondBookMark (1-5 pages)
> >> >  -page1
> >> >  -page2
> >> >  -page3
> >> >  -page4
> >> >  -page5|_thirdBookMark (1-8 pages)
> >> >  -page1
> >> >  -page2
> >> >  -page3
> >> >  - .
> >> >  - .
> >> >  -page8|_FourthBookMark|_|_|_lastBookMark
> >> >
> >> >
> >> > Thanks
> >> >
> >> > Mustafa
> >> >
> >>
> >
> >
>

Re: Iterate and access the pages under sub bookmark

Posted by Mustafa Farooqui <mu...@gmail.com>.
Adding to my previous email this is the basic structure

*PDF -> MainBookMark -> subBookMark1 -> pages( 1- 10 etc..)*




On Fri, Jul 14, 2017 at 2:33 PM, Mustafa Farooqui <mustafafarooqui@gmail.com
> wrote:

> Below is my code and pdf structure which am working on. I am stuck at a
> point where i am trying to get the pages which are under the "subBookMark1".
> These pages are basically forms which are more than one pages. I am not
> sure how to iterate over these pages under subBookMark1. Like page 1, page2
> , page 3 etc.  Hope this information helps you to understand my issue?
>
>
> Below is my PDF structure
>
> *MainBookMarkName
> |_subBookMark1 (1-10 pages)
>  -page1
>  -page2
>  -page3
>  -page4
>  - .
>  - .
>  -page10
> |_**subBookMark2** (1-5 pages)*
> * -page1
>  -page2
>  -page3
>  -page4
>  -page5
> |_**subBookMark3 ** (1-8 pages)*
> * -page1
>  -page2
>  -page3
>  - .
>  - .
>  -page8
> |_**subBookMark4*
> *
> |_
> |_
> |_**subBookMark5*
>
> My Code
>
> public static PDPage printBookmark(PDDocument document, PDOutlineNode
> node, String indentation)
> throws IOException {
> PDOutlineItem mainBookMark= node.getFirstChild();
> PDOutlineItem subBookMark1= mainBookMark.getFirstChild();
>
> while (subBookMark1!= null) {
> System.out.println(subBookMark1.getTitle());
>
> if (subBookMark1.getDestination() instanceof PDPageDestination) {
>
> if (subBookMark1.getTitle().equals("subBookMark1 Title")) {
>
>
> PDPageDestination pd = (PDPageDestination) subBookMark1.getDestination();
>
> System.out.println("Destination page: " + (pd.retrievePageNumber() + 1));
>
> return pd.getPage();
>
> }
> }
> printBookmark(document, subBookMark1, indentation + "    ");
> subBookMark1= subBookMark1.getNextSibling();
> }
> return null;
>
> }
>
>
>
> On Fri, Jul 14, 2017 at 11:10 AM, Gilad Denneboom <
> gilad.denneboom@gmail.com> wrote:
>
>> What exactly is the issue? Do you know how to access the Outline root? Do
>> you know how to proceed from there to the children/siblings (this will
>> require a recursive function, unless you know there is only a fixed amount
>> of levels in the bookmark hierarchy)? Do you know how to access the
>> action(s) associated with each bookmark?
>> It would be helpful if you could let us know to which point you've
>> arrived,
>> and where you got stuck...
>>
>> On Fri, Jul 14, 2017 at 4:55 PM, Mustafa Farooqui <
>> mustafafarooqui@gmail.com
>> > wrote:
>>
>> > Hi,
>> >
>> > I am trying to access the pages which are under the sub bookmark .
>> > Below is the structure of the pdf file and under it there sub
>> > bookmarks. These sub bookmarks have multiple pages which are basically
>> > forms extended to more than one page. I am able to get to those sub
>> > bookmark. However, cannot iterate over those pages or get any specific
>> > page i need to edit or resize?
>> >
>> > Can anyone please suggest or help? I can share the code but cannot
>> > share the confidential pdf which I am working on. I tried  finding the
>> > sample document online but couldn't find any.  My question is similar
>> > to the below link which i found on stackover flow.
>> >
>> > https://stackoverflow.com/questions/45002625/how-to-
>> > load-the-pages-which-are-under-the-sub-bookmark-using-pdf-box
>> >
>> >
>> > Below is the structure of my PDF document
>> >
>> > MainBookMarkName|_firstBookMark (1-10 pages)
>> >  -page1
>> >  -page2
>> >  -page3
>> >  -page4
>> >  - .
>> >  - .
>> >  -page10|_secondBookMark (1-5 pages)
>> >  -page1
>> >  -page2
>> >  -page3
>> >  -page4
>> >  -page5|_thirdBookMark (1-8 pages)
>> >  -page1
>> >  -page2
>> >  -page3
>> >  - .
>> >  - .
>> >  -page8|_FourthBookMark|_|_|_lastBookMark
>> >
>> >
>> > Thanks
>> >
>> > Mustafa
>> >
>>
>
>

Re: Iterate and access the pages under sub bookmark

Posted by Mustafa Farooqui <mu...@gmail.com>.
Below is my code and pdf structure which am working on. I am stuck at a
point where i am trying to get the pages which are under the "subBookMark1".
These pages are basically forms which are more than one pages. I am not
sure how to iterate over these pages under subBookMark1. Like page 1, page2
, page 3 etc.  Hope this information helps you to understand my issue?


Below is my PDF structure

*MainBookMarkName
|_subBookMark1 (1-10 pages)
 -page1
 -page2
 -page3
 -page4
 - .
 - .
 -page10
|_**subBookMark2** (1-5 pages)*
* -page1
 -page2
 -page3
 -page4
 -page5
|_**subBookMark3 ** (1-8 pages)*
* -page1
 -page2
 -page3
 - .
 - .
 -page8
|_**subBookMark4*
*
|_
|_
|_**subBookMark5*

My Code

public static PDPage printBookmark(PDDocument document, PDOutlineNode node,
String indentation)
throws IOException {
PDOutlineItem mainBookMark= node.getFirstChild();
PDOutlineItem subBookMark1= mainBookMark.getFirstChild();

while (subBookMark1!= null) {
System.out.println(subBookMark1.getTitle());

if (subBookMark1.getDestination() instanceof PDPageDestination) {

if (subBookMark1.getTitle().equals("subBookMark1 Title")) {


PDPageDestination pd = (PDPageDestination) subBookMark1.getDestination();

System.out.println("Destination page: " + (pd.retrievePageNumber() + 1));

return pd.getPage();

}
}
printBookmark(document, subBookMark1, indentation + "    ");
subBookMark1= subBookMark1.getNextSibling();
}
return null;

}



On Fri, Jul 14, 2017 at 11:10 AM, Gilad Denneboom <gilad.denneboom@gmail.com
> wrote:

> What exactly is the issue? Do you know how to access the Outline root? Do
> you know how to proceed from there to the children/siblings (this will
> require a recursive function, unless you know there is only a fixed amount
> of levels in the bookmark hierarchy)? Do you know how to access the
> action(s) associated with each bookmark?
> It would be helpful if you could let us know to which point you've arrived,
> and where you got stuck...
>
> On Fri, Jul 14, 2017 at 4:55 PM, Mustafa Farooqui <
> mustafafarooqui@gmail.com
> > wrote:
>
> > Hi,
> >
> > I am trying to access the pages which are under the sub bookmark .
> > Below is the structure of the pdf file and under it there sub
> > bookmarks. These sub bookmarks have multiple pages which are basically
> > forms extended to more than one page. I am able to get to those sub
> > bookmark. However, cannot iterate over those pages or get any specific
> > page i need to edit or resize?
> >
> > Can anyone please suggest or help? I can share the code but cannot
> > share the confidential pdf which I am working on. I tried  finding the
> > sample document online but couldn't find any.  My question is similar
> > to the below link which i found on stackover flow.
> >
> > https://stackoverflow.com/questions/45002625/how-to-
> > load-the-pages-which-are-under-the-sub-bookmark-using-pdf-box
> >
> >
> > Below is the structure of my PDF document
> >
> > MainBookMarkName|_firstBookMark (1-10 pages)
> >  -page1
> >  -page2
> >  -page3
> >  -page4
> >  - .
> >  - .
> >  -page10|_secondBookMark (1-5 pages)
> >  -page1
> >  -page2
> >  -page3
> >  -page4
> >  -page5|_thirdBookMark (1-8 pages)
> >  -page1
> >  -page2
> >  -page3
> >  - .
> >  - .
> >  -page8|_FourthBookMark|_|_|_lastBookMark
> >
> >
> > Thanks
> >
> > Mustafa
> >
>

Re: Iterate and access the pages under sub bookmark

Posted by Gilad Denneboom <gi...@gmail.com>.
What exactly is the issue? Do you know how to access the Outline root? Do
you know how to proceed from there to the children/siblings (this will
require a recursive function, unless you know there is only a fixed amount
of levels in the bookmark hierarchy)? Do you know how to access the
action(s) associated with each bookmark?
It would be helpful if you could let us know to which point you've arrived,
and where you got stuck...

On Fri, Jul 14, 2017 at 4:55 PM, Mustafa Farooqui <mustafafarooqui@gmail.com
> wrote:

> Hi,
>
> I am trying to access the pages which are under the sub bookmark .
> Below is the structure of the pdf file and under it there sub
> bookmarks. These sub bookmarks have multiple pages which are basically
> forms extended to more than one page. I am able to get to those sub
> bookmark. However, cannot iterate over those pages or get any specific
> page i need to edit or resize?
>
> Can anyone please suggest or help? I can share the code but cannot
> share the confidential pdf which I am working on. I tried  finding the
> sample document online but couldn't find any.  My question is similar
> to the below link which i found on stackover flow.
>
> https://stackoverflow.com/questions/45002625/how-to-
> load-the-pages-which-are-under-the-sub-bookmark-using-pdf-box
>
>
> Below is the structure of my PDF document
>
> MainBookMarkName|_firstBookMark (1-10 pages)
>  -page1
>  -page2
>  -page3
>  -page4
>  - .
>  - .
>  -page10|_secondBookMark (1-5 pages)
>  -page1
>  -page2
>  -page3
>  -page4
>  -page5|_thirdBookMark (1-8 pages)
>  -page1
>  -page2
>  -page3
>  - .
>  - .
>  -page8|_FourthBookMark|_|_|_lastBookMark
>
>
> Thanks
>
> Mustafa
>