-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkitdown_pdf.py
More file actions
34 lines (23 loc) 路 1.02 KB
/
Copy pathmarkitdown_pdf.py
File metadata and controls
34 lines (23 loc) 路 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import sys
import timeit
from loguru import logger
from markitdown import MarkItDown
# Add a console sink
# logger.add(sys.stderr, level="DEBUG")
timestamp_yyyymmdd_hhmm = timeit.default_timer()
# Add a file sink
# logger.add(f"log_.log", level="INFO")
md = MarkItDown(enable_plugins=False) # Set to True to enable plugins
input_file_path = "input/sample.pdf" # Replace with your PDF file path
output_file_path = os.path.join("output", "markitdown_extracted_text.txt")
timeit_start = timeit.default_timer()
print(f"Processing {input_file_path}...")
logger.info(f"Processing {input_file_path}...")
result = md.convert(input_file_path)
contents = result.text_content # Extract the text content from the conversion result
with open(output_file_path, "w", encoding="utf-8") as f:
f.write(contents)
timeit_end = timeit.default_timer()
print(f"Finished processing {input_file_path} in {timeit_end - timeit_start:.2f} seconds.")
logger.info(f"Finished processing {input_file_path} in {timeit_end - timeit_start:.2f} seconds.")