@@ -233,13 +233,10 @@ def __new__(
233233 try :
234234 return decimal .Decimal .__new__ (cls , str_ (value ), context )
235235 except Exception :
236- try :
237- return decimal .Decimal .__new__ (cls , str (value ))
238- except decimal .InvalidOperation :
239- # If this isn't a valid decimal (happens in malformed PDFs)
240- # fallback to 0
241- logger_warning (f"Invalid FloatObject { value } " , __name__ )
242- return decimal .Decimal .__new__ (cls , "0" )
236+ # If this isn't a valid decimal (happens in malformed PDFs)
237+ # fallback to 0
238+ logger_warning (f"FloatObject ({ value } ) invalid; use 0.0 instead" , __name__ )
239+ return decimal .Decimal .__new__ (cls , "0.0" )
243240
244241 def __repr__ (self ) -> str :
245242 if self == self .to_integral ():
@@ -271,8 +268,11 @@ class NumberObject(int, PdfObject):
271268 NumberPattern = re .compile (b"[^+-.0-9]" )
272269
273270 def __new__ (cls , value : Any ) -> "NumberObject" :
274- val = int (value )
275- return int .__new__ (cls , val )
271+ try :
272+ return int .__new__ (cls , int (value ))
273+ except ValueError :
274+ logger_warning (f"NumberObject({ value } ) invalid; use 0 instead" , __name__ )
275+ return int .__new__ (cls , 0 )
276276
277277 def as_numeric (self ) -> int :
278278 return int (repr (self ).encode ("utf8" ))
0 commit comments