Using GetObjectAttribute in C++ to retrieve Objects

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
jim90291
Posts: 13
Joined: Wed Nov 12 2003

Using GetObjectAttribute in C++ to retrieve Objects

Post by jim90291 »

I see the example and explanation of using GetObjectAttribute to retrieve the list of objects in a document, but am unable to implement it into my code. Two problems, one, the example uses VB, and I use C++, and don't know how to translate, and two, I've never use a VARIANT before.

So my questions: (1) Can anyone give me brief instructions on how to use the GetObjectAttribute to get the list of objects, (2) Brief instructions on how to traverse this list, and get the "Name" of each object, so I can thus get its subsequent attributes.

I have no problems using all the other fxns, but the use of the VARIANT (if that's indeed the C++ class being used), throws me.

Regards,
Jim
Dany
Amyuni Team
Posts: 113
Joined: Wed Sep 11 2002
Location: Montreal.
Contact:

Post by Dany »

Here's a C++ sample that goes through all the objects in a page and fills a listbox.

m_pdf.Open( "c:\\temp\\test.pdf", "" );
long p, limit = m_pdf.GetPageCount();
long object, objcount;
CString cs;
VARIANT objects;
// loop through all pages
for ( p = 0; p < limit; p++ )
{
// get object array for a page
cs.Format( _T("Pages[%d]"), p + 1 );
objects = m_pdf.GetObjectAttribute( cs, _T("Objects") );

// this returns a value of type SAFEARRAY
ASSERT( objects.vt == VT_SAFEARRAY );
SafeArrayLock( objects.parray );

// process objects here...
SafeArrayGetUBound( objects.parray, 1, &objcount );
// loop through all objects on the page
for ( object = 0; object < objcount; object++ )
{
// CacObject is a class created by the MFC class wizard
CacObject obj( ((LPDISPATCH *)objects.parray->pvData)[object] );
m_list.AddString( obj.GetName() );
}

SafeArrayUnlock( objects.parray );
VariantClear( &objects );
}
jim90291
Posts: 13
Joined: Wed Nov 12 2003

so far so good...

Post by jim90291 »

thanks! this seems to work..

however, my class definition of CacObject does not include GetName. I am using 1.09 of the PDFCreator. Is there a new version that contains more member variables?

Regards,
Jim Smith
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

The latest version of the PDF Creator is 1.50b. You can download it at our site www.amyuni.com
jim90291
Posts: 13
Joined: Wed Nov 12 2003

problem...

Post by jim90291 »

ok, getting close, my problem now is that when the line:

objects = m_pdf.GetObjectAttribute(cs, _T("Objects"));

instead of returning a value to the objects variant, it immediately drops out and returns from the fxn.

any explanation would be FANTASTIC!!
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hi,

I am not a C++ developer myself so I can't be of great help here :( but you can find a full C++ sample along with the demo version of the PDF Creator.

I hope a C++ developer using the PDF Creator will read your post and be able to help you.

Have a nice day!
Post Reply