File size: 472 Bytes
86a4642
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
import pymupdf4llm
import re

def load_pdf(file_path: str) -> str:
    md_text = pymupdf4llm.to_markdown(file_path)
    # remove picture blocks and HTML artifacts
    md_text = re.sub(r'\*\*----- Start of picture text -----\*\*.*?\*\*----- End of picture text -----\*\*', '', md_text, flags=re.DOTALL)
    md_text = re.sub(r'<br>', '\n', md_text)
    md_text = re.sub(r'==>.*?<==', '', md_text)
    md_text = re.sub(r'\n{3,}', '\n\n', md_text)
    return md_text