@@ -601,14 +601,17 @@ def load(
601601 path_or_stream : Union [str , Path , BytesIO ],
602602 lazy : bool = True ,
603603 boundary_type : PdfPageBoundaryType = PdfPageBoundaryType .CROP_BOX ,
604+ password : Optional [str ] = None ,
604605 ) -> PdfDocument :
605606
606607 if isinstance (path_or_stream , str ):
607608 path_or_stream = Path (path_or_stream )
608609
609610 if isinstance (path_or_stream , Path ):
610611 key = f"key={ str (path_or_stream )} " # use filepath as internal handle
611- success = self ._load_document (key = key , filename = str (path_or_stream ))
612+ success = self ._load_document (
613+ key = key , filename = str (path_or_stream ), password = password
614+ )
612615
613616 elif isinstance (path_or_stream , BytesIO ):
614617 hasher = hashlib .sha256 (usedforsecurity = False )
@@ -632,17 +635,22 @@ def load(
632635 else :
633636 raise RuntimeError (f"Failed to load document with key { key } " )
634637
635- def _load_document (self , key : str , filename : str ) -> bool :
638+ def _load_document (
639+ self , key : str , filename : str , password : Optional [str ] = None
640+ ) -> bool :
636641 """Load a document by key and filename.
637642
638643 Parameters:
639644 key (str): The unique key to identify the document.
640645 filename (str): The path to the document file to load.
646+ password (str, optional): Optional password for password-protected files
641647
642648 Returns:
643649 bool: True if the document was successfully loaded, False otherwise.)")
644650 """
645- return self .parser .load_document (key = key , filename = filename .encode ("utf8" ))
651+ return self .parser .load_document (
652+ key = key , filename = filename .encode ("utf8" ), password = password
653+ )
646654
647655 def _load_document_from_bytesio (self , key : str , data : BytesIO ) -> bool :
648656 """Load a document by key from a BytesIO-like object.
0 commit comments