You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ilya Sazonov <po...@gmail.com> on 2012/04/03 12:09:44 UTC

How to retrieve object number for PDPage?

Suppose I have a PDPage object. How do I get it's object number?

The only class which has getObjectNumber method is COSObject, and PDPage
implements COSObjectable, which means that it has getCOSObject method. But
this method returns COSBase. COSObject is a subclass of COSBase, but in
case of PDPage getCOSObject always returns COSDictionary. So this way of
getting object number lead me to nowhere.

I looked through the codebase and found a method in PDDocument, where
COSObject for PDPage is retrieved. It looks like this

    private void processListOfPageReferences(List<Object> pageNodes)
    {
        int numberOfNodes = pageNodes.size();
        for(int i=0; i < numberOfNodes; ++i)
        {
            Object pageOrArray = pageNodes.get(i);
            if(pageOrArray instanceof PDPage)
            {
                COSArray pageArray =
((COSArrayList)(((PDPage)pageOrArray).getParent()).getKids()).toList();
                parseCatalogObject((COSObject)pageArray.get(i));
            }
            else if(pageOrArray instanceof PDPageNode)
            {

processListOfPageReferences(((PDPageNode)pageOrArray).getKids());
            }
        }
    }

To be more specific I looked at these lines of code

if(pageOrArray instanceof PDPage)
{
    COSArray pageArray =
((COSArrayList)(((PDPage)pageOrArray).getParent()).getKids()).toList();
    parseCatalogObject((COSObject)pageArray.get(i));
}

The fact that pageOrArray wasn't used to fetch corresponding COSObject
makes me believe, that it is not possible.
But I can't understand how it is possible. I mean pageArray.get(i) should
be the same object as pageOrArray.getCOSObject(), but it is obviously
wrong...