I propose the following function is added to COSArrayList. public COSArray toList() { COSArray copy = new COSArray(); for(int i=0; i < array.size(); ++i) copy.add(array.get(i)); return copy; }
This returns a copy of the array to ensure the callers can't modify the internal array variable. Callers already have access to this information as it is the same data as is returned by toString() just in a more useful format. If it's OK to give the callers the ability to modify array directly, a reference could simply be returned. I needed this because I got the "indirect reference to a page object" from the target listed in a GoTo action and needed the page number. By using the method above I was able to get the page references in the catalog and thus was able to determine the page number based on the page object id I had. -- Thanks, Adam Adam Nichols/UR/CER/XLDynamics 05/22/2009 15:21 To pdfbox-dev@incubator.apache.org cc Subject Get page number for bookmark I'm trying to parse PDF files, look at all the bookmarks, determine what page they are on, and then split the document based on the bookmarks. For now, I'm not worried about supporting name based bookmarks. I can loop through the bookmarks with no problem (like the PrintBookmarks example) but the PDOutlineItem objects all have a null Destination. I looked at the PDF in a hex editor and read the PDF spec, and it looks like this is because the bookmark doesn't have a "Dest", on the bookmark entry. Instead it seems to refer to a "GoTo" action which then references page "2 0 R". Here's my bookmark: 102 0 obj <</Parent 101 0 R/A 100 0 R/Next 104 0 R/Title(A002\r)>> endobj And the action which I believe it's referencing. 100 0 obj <</D[2 0 R/FitH 795]/S/GoTo>> endobj If I dig into the COSDictionary, I can pull out the {2, 0} in a COSObject. My problem now is determining which page number number that is; I don't see anything in the library which allows me to do this. It seems strange that nobody has even desired to get a page number from a bookmark, but I checked the users mailing list, searched the mailing list archives and spent about an hour on Google trying to track down a solution. If this feature is missing, I have no problem adding it, but I'd need some help in making sure I do it as efficiently as possible and put it in the correct place in the library. Perhaps it'd be as easy as adding an accessor for the page object id in the PDPage class? Thanks, Adam