Hi,

Yes difference is that GetReference() must be called on object which is of
type ePdfDataType_Reference and that object is casted to PdfReference.
Reference() can be called on indirect object and it returns PdfReference
which "points" to it.

This is indirect object which is dictionary, Reference() returns (4, 0) and
GetReference throws exception:

4 0 obj<</Font <</F1 5 0 R>>>>
endobj

This dictionary contains one element with key name Font with value which is
direct object so Reference() will return (0, 0) and GetReference() throws.

Probably in your case it looks more like this:

4 0 obj<</Font 6 0 R>>
endobj
6 0 obj<</F1 5 0 R>>
endobj

Here that dictionary contains one element with key name Font with value
which is direct object of type reference to indirect object of type
dictionary, Reference() will return (0, 0) and GetReference() returns (6,
0).

Instead of trying to get indirect object using
"document.GetObjects()->GetObject(" and passing PdfReference you can
use GetIndirectKey() or MustGetIndirectKey() which looks like this in
podofo sources:

```

PdfObject* PdfObject::GetIndirectKey( const PdfName & key ) const
{
    const PdfObject* pObj = NULL;

    if( this->IsDictionary() && this->GetDictionary().HasKey( key ) )
    {
        pObj = this->GetDictionary().GetKey( key );
        if( pObj->IsReference() )
        {
            if( !m_pOwner )
            {
                PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, "Object
is a reference but does not have an owner!" );
            }

            pObj = m_pOwner->GetObject( pObj->GetReference() );
        }
        else
            const_cast<PdfObject*>(pObj)->SetOwner( GetOwner() );// even
directs might want an owner...
    }

    // DominikS: TODO Remove const on GetIndirectKey
    return const_cast<PdfObject*>(pObj);
}

```

As you can see it will do the job for your whether or not that object is
direct or indirect. It handles getting things from dictionaries by keys.


What I want to achieve is reasonably simple: I want to list all XObjects
> and their subtype for a given page.


Also note that not only pages have their resources. There can be also
resources in acroforms and annotations on that page.



On Tue, Sep 10, 2019 at 4:01 PM Pietro Paolini <
pietro.paol...@cognitivecredit.com> wrote:

> Hi all,
>
> Problem solved .... I needed to call GetReference() to actually load the
> reference .....
>
>
> On 10/09/2019 08:32, zyx wrote:
> > On Mon, 2019-09-09 at 11:02 +0100, Pietro Paolini wrote:
> >> What the correct approach to do what I want with PoDoFo ?
> >
> >       Hi,
> > I would try something like this while cycle:
> >
> https://sourceforge.net/p/podofo/code/HEAD/tree/podofo/trunk/tools/podofoimgextract/ImageExtractor.cpp#l60
> >
> >       Bye,
> >       zyx
> >
> >
> >
> > _______________________________________________
> > Podofo-users mailing list
> > Podofo-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/podofo-users
> >
>
>
> _______________________________________________
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to