MCPcopy Index your code
hub / github.com/clips/pattern / PDFDocument

Class PDFDocument

pattern/web/pdf/pdfparser.py:281–576  ·  view source on GitHub ↗

PDFDocument object represents a PDF document. Since a PDF file can be very big, normally it is not loaded at once. So PDF document has to cooperate with a PDF parser in order to dynamically import the data as processing goes. Typical usage: doc = PDFDocument() doc.set_p

Source from the content-addressed store, hash-verified

279## PDFDocument
280##
281class PDFDocument(object):
282
283 """PDFDocument object represents a PDF document.
284
285 Since a PDF file can be very big, normally it is not loaded at
286 once. So PDF document has to cooperate with a PDF parser in order to
287 dynamically import the data as processing goes.
288
289 Typical usage:
290 doc = PDFDocument()
291 doc.set_parser(parser)
292 doc.initialize(password)
293 obj = doc.getobj(objid)
294
295 """
296
297 debug = 0
298
299 def __init__(self, caching=True):
300 self.caching = caching
301 self.xrefs = []
302 self.info = []
303 self.catalog = None
304 self.encryption = None
305 self.decipher = None
306 self._parser = None
307 self._cached_objs = {}
308 self._parsed_objs = {}
309 return
310
311 def set_parser(self, parser):
312 "Set the document to use a given PDFParser object."
313 if self._parser: return
314 self._parser = parser
315 # Retrieve the information of each header that was appended
316 # (maybe multiple times) at the end of the document.
317 self.xrefs = parser.read_xref()
318 for xref in self.xrefs:
319 trailer = xref.get_trailer()
320 if not trailer: continue
321 # If there's an encryption info, remember it.
322 if 'Encrypt' in trailer:
323 #assert not self.encryption
324 self.encryption = (list_value(trailer['ID']),
325 dict_value(trailer['Encrypt']))
326 if 'Info' in trailer:
327 self.info.append(dict_value(trailer['Info']))
328 if 'Root' in trailer:
329 # Every PDF file must have exactly one /Root dictionary.
330 self.catalog = dict_value(trailer['Root'])
331 break
332 else:
333 raise PDFSyntaxError('No /Root object! - Is this really a PDF?')
334 if self.catalog.get('Type') is not LITERAL_CATALOG:
335 if STRICT:
336 raise PDFSyntaxError('Catalog not found!')
337 return
338

Callers 1

process_pdfFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…