jcushman/pdfquery

Getting `TypeError: 'PDFObjRef' object is not iterable`

Closed this issue · 3 comments

When trying to load a PDF, I get the following error

TypeError: 'PDFObjRef' object is not iterable

The error happens at pdfquery/pdfquery.py line 631

def _add_annots(self, layout, annots):
        """Adds annotations to the layout object
        """
        if annots: # and not isinstance(annots, PDFObjRef):
            for annot in annots:
                annot = annot.resolve()
                if annot.get('Rect') is not None:
                    annot['bbox'] = annot.pop('Rect')  # Rename key
                    annot = self._set_hwxy_attrs(annot)
                try:
                    annot['URI'] = annot['A']['URI']
                except KeyError:
                    pass
                for k, v in annot.iteritems():
                    if not isinstance(v, basestring):
                        annot[k] = unicode_decode_object(v)
                elem = parser.makeelement('Annot', annot)
                layout.add(elem)
        return layout

The error goes away by adding the second check that is commented out from the above code

Can you by any chance point to a PDF that has this problem for testing? There's probably a better solution than that second check, but I'd like to test. Thanks!

Fixed in version 0.3.1 on PyPI. Thanks for the report.

Confirmed working