pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ilya Sazonov <poxvu...@gmail.com>
Subject How to retrieve object number for PDPage?
Date Tue, 03 Apr 2012 10:09:44 GMT
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...

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message