MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / parse_pdf

Function parse_pdf

demo/Paper2Poster/utils/src/model_utils.py:98–141  ·  view source on GitHub ↗

Parse a PDF file and extract text and images. Args: pdf_path (str): The path to the PDF file. output_path (str): The directory to save the extracted content. model_lst (list): A list of models for processing the PDF. Returns: str: The full text extracte

(
    pdf_path: str,
    output_path: str = None,
    model_lst: list = None,
    save_file: bool = True,
)

Source from the content-addressed store, hash-verified

96
97
98def parse_pdf(
99 pdf_path: str,
100 output_path: str = None,
101 model_lst: list = None,
102 save_file: bool = True,
103) -> str:
104 """
105 Parse a PDF file and extract text and images.
106
107 Args:
108 pdf_path (str): The path to the PDF file.
109 output_path (str): The directory to save the extracted content.
110 model_lst (list): A list of models for processing the PDF.
111
112 Returns:
113 str: The full text extracted from the PDF.
114 """
115 if save_file:
116 os.makedirs(output_path, exist_ok=True)
117 config_parser = ConfigParser(
118 {
119 "output_format": "markdown",
120 }
121 )
122 converter = PdfConverter(
123 config=config_parser.generate_config_dict(),
124 artifact_dict=model_lst,
125 processor_list=config_parser.get_processors(),
126 renderer=config_parser.get_renderer(),
127 )
128 rendered = converter(pdf_path)
129 full_text, _, images = text_from_rendered(rendered)
130 if save_file:
131 with open(pjoin(output_path, "source.md"), "w+", encoding="utf-8") as f:
132 f.write(full_text)
133 for filename, image in images.items():
134 image_filepath = os.path.join(output_path, filename)
135 image.save(image_filepath, "JPEG")
136 with open(pjoin(output_path, "meta.json"), "w+") as f:
137 f.write(json.dumps(rendered.metadata, indent=4))
138
139 if not save_file:
140 return full_text, rendered
141 return full_text
142
143
144# def get_text_embedding(

Callers 3

get_poster_textFunction · 0.90
parse_pdfsFunction · 0.90
parse_rawFunction · 0.90

Calls 1

saveMethod · 0.45

Tested by

no test coverage detected