How can I detect with PDFNet whether a PDF object is free or not, given the object number?

29 views
Skip to first unread message

Support

unread,
Feb 26, 2013, 1:30:07 PM2/26/13
to pdfne...@googlegroups.com
Q: How can I detect with PDFNet whether an object is free or not, given the object number?

So far, I've seen three behaviors for free objects:

 

- SDFDoc.GetObj() throws an exception

- SDFDoc.GetObj() succeeds and GetObjNum() for the object returns 0

 

Some PDF documents (erroneously) use "0000000000 00000 n" in the xref table for free objects (and they created by an Adobe product!). We would like to detect this type of errors and to add some special handling.
 
--------
A:
 
To use a random obj from the file you need to make sure that obj is not NULL and that it is not free (i.e. obj && !obj.IsFree()).
 

For a concrete example, please take a look at a second code snippet in ImageExtract sample project:

 

SDFDoc& cos_doc=doc.GetSDFDoc();

int num_objs = cos_doc.XRefSize();

for(int i=1; i<num_objs; ++i)  {

   Obj obj = cos_doc.GetObj(i);

   if(obj && !obj.IsFree() && ... ) {

          ....

   }

}

Reply all
Reply to author
Forward
0 new messages