It helps to understand how PDFs are structured (objects, references, named 
destinations, etc.), but the following should help you either way.

First, you'll need to get the object id and generation that the bookmark 
points to, like this:
        targetPageRef = 
(COSObject)((COSArray)item.getAction().getCOSDictionary().getDictionaryObject("D")).get(0);

But sometimes it's not an indirect reference, but rather a named 
destination.  This is less common, but it does happen and is completely 
valid according to the PDF spec.  To make sure you can handle those cases, 
you'll have to do something like this:
        PDDestination dest = item.getDestination();
        targetPageRef = (COSObject)((COSArray)dest.getCOSObject()).get(0);

Once you have the reference, it's just a matter of looking it up in the 
page map...
        String objStr = 
String.valueOf(targetPageRef.getObjectNumber().intValue());
        String genStr = 
String.valueOf(targetPageRef.getGenerationNumber().intValue());
        Integer pageNumber = 
(Integer)doc.getPageMap().get(objStr+","+genStr);

Watch out for NULL values.  They can appear virtually anywhere, and if you 
don't check for them, you'll be sure to eventually get some PDF which will 
cause a NullPointerException.


In the examples above "item" is of type PDOutlineItem
PDDocumentOutline root = doc.getDocumentCatalog().getDocumentOutline();
if(root != null) { // if there's no outline, there are certainly no 
bookmarks!
        PDOutlineItem item = root.getFirstChild();
}

And subsequent bookmarks can then be obtained via: item.getFirstChild() 
and item.getNextSibling()

---- 
Thanks,
Adam





From:
"Cescky" <[email protected]>
To:
"users" <[email protected]>
Date:
04/02/2011 04:24
Subject:
About bookmark



Hi,


I need to find the page number which they have the same content of the 
bookmark.


I use the following code to get the content of the bookmark, but is their 
any way to find  the page number of each bookmark? Then i will compare the 
bookmark content. Finally, i can get the page number containing the same 
bookmark content.


CODE:
PDOutlineItem child = item.getFirstChild();child.getTitle()




- FHA 203b; 203k; HECM; VA; USDA; Conventional 
- Warehouse Lines; FHA-Authorized Originators 
- Lending and Servicing in over 45 States 
www.swmc.com   -  www.simplehecmcalculator.com   
Visit  www.swmc.com/resources   for helpful links on Training, Webinars, Lender 
Alerts and Submitting Conditions  

This email and any content within or attached hereto from Sun West Mortgage 
Company, Inc. is confidential and/or legally privileged. The information is 
intended only for the use of the individual or entity named on this email. If 
you are not the intended recipient, you are hereby notified that any 
disclosure, copying, distribution or taking any action in reliance on the 
contents of this email information is strictly prohibited, and that the 
documents should be returned to this office immediately by email. Receipt by 
anyone other than the intended recipient is not a waiver of any privilege. 
Please do not include your social security number, account number, or any other 
personal or financial information in the content of the email. Should you have 
any questions, please call (800) 453 7884.  

Reply via email to