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
Using GetObjectAttribute in C++ to retrieve Objects
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 );
}
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 );
}
so far so good...
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
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
The latest version of the PDF Creator is 1.50b. You can download it at our site www.amyuni.com
problem...
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!!
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!!