@@ -229,7 +229,16 @@ def root_object(self) -> DictionaryObject:
229
229
self ._validated_root = o
230
230
logger_warning (f"Root found at { o .indirect_reference !r} " , __name__ )
231
231
break
232
- if self ._validated_root is None :
232
+ if self ._validated_root is None :
233
+ if not is_null_or_none (root ) and "/Pages" in cast (DictionaryObject , cast (PdfObject , root ).get_object ()):
234
+ logger_warning (
235
+ f"Possible root found at { cast (PdfObject , root ).indirect_reference !r} , but missing /Catalog key" ,
236
+ __name__
237
+ )
238
+ self ._validated_root = cast (
239
+ DictionaryObject , cast (PdfObject , root ).get_object ()
240
+ )
241
+ else :
233
242
raise PdfReadError ("Cannot find Root object in pdf" )
234
243
return self ._validated_root
235
244
@@ -245,13 +254,12 @@ def _info(self) -> Optional[DictionaryObject]:
245
254
info = self .trailer .get (TK .INFO , None )
246
255
if is_null_or_none (info ):
247
256
return None
248
- else :
249
- info = info .get_object ()
250
- if not isinstance (info , DictionaryObject ):
251
- raise PdfReadError (
252
- "Trailer not found or does not point to document information directory"
253
- )
254
- return info
257
+ info = info .get_object ()
258
+ if not isinstance (info , DictionaryObject ):
259
+ raise PdfReadError (
260
+ "Trailer not found or does not point to document information directory"
261
+ )
262
+ return info
255
263
256
264
@property
257
265
def _ID (self ) -> Optional [ArrayObject ]:
@@ -316,8 +324,7 @@ def _get_page_number_by_indirect(
316
324
else :
317
325
idnum = indirect_reference .idnum
318
326
assert self ._page_id2num is not None , "hint for mypy"
319
- ret = self ._page_id2num .get (idnum , None )
320
- return ret
327
+ return self ._page_id2num .get (idnum , None )
321
328
322
329
def _get_object_from_stream (
323
330
self , indirect_reference : IndirectObject
@@ -913,10 +920,8 @@ def _read_xref(self, stream: StreamType) -> Optional[int]:
913
920
)
914
921
stream .seek (p , 0 )
915
922
if "/Prev" in new_trailer :
916
- startxref = new_trailer ["/Prev" ]
917
- return startxref
918
- else :
919
- return None
923
+ return new_trailer ["/Prev" ]
924
+ return None
920
925
921
926
def _read_xref_other_error (
922
927
self , stream : StreamType , startxref : int
@@ -988,8 +993,7 @@ def get_entry(i: int) -> Union[int, Tuple[int, ...]]:
988
993
# W array indicates...the default value shall be used
989
994
if i == 0 :
990
995
return 1 # First value defaults to 1
991
- else :
992
- return 0
996
+ return 0
993
997
994
998
def used_before (num : int , generation : Union [int , Tuple [int , ...]]) -> bool :
995
999
# We move backwards through the xrefs, don't replace any.
0 commit comments