File size: 473 Bytes
6085b61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import fitz


class ExtractionError(Exception):
    pass


def extract_structured(file_path, password=None):
    doc = fitz.Document(file_path)
    if doc.is_encrypted:
        if password is None:
            raise ExtractionError(
                "PDF is password protected. Pass password= to extract()"
            )
        if not doc.authenticate(password):
            raise ExtractionError("Incorrect password for PDF.")
    # rest of the function implementation...