def ingest(pdf_input: Pdf) -> List[Union[TextElement, ImageElement]]:
    """Parse PDF and return a list of TextElement and ImageElement objects."""
    elements = []
    page_layouts = pdf_input.extract_layout_pages()

    for page_num, page_layout in enumerate(page_layouts):
        page_width = page_layout.width
        page_height = page_layout.height
        page_elements = []
        for element in page_layout:
            if isinstance(element, LTTextContainer):
                lines = []
                for text_line in element:
                    if isinstance(text_line, LTTextLine):
                        lines.append(_create_line_element(text_line))
                if not lines:
                    continue
                bbox = _get_bbox(lines)

                page_elements.append(
                    TextElement(
                        bbox=Bbox(
                            x0=bbox[0],
                            y0=bbox[1],
                            x1=bbox[2],
                            y1=bbox[3],
                            page=page_num,
                            page_width=page_width,
                            page_height=page_height,
                        ),
                        text="\n".join(line.text for line in lines),
                        lines=tuple(lines),
                    )
                )
            elif isinstance(element, LTFigure):
                for e in element:
                    if isinstance(e, LTImage):
                        mime_type = _get_mime_type(e)
                        if mime_type:
                            if mime_type == "image/png":
                                img_data = _process_png_image(e)
                            else:
                                img_data = e.stream.get_data()
                            if img_data:
                                base64_string = base64.b64encode(img_data).decode(
                                    "utf-8"
                                )
                                page_elements.append(
                                    ImageElement(
                                        bbox=Bbox(
                                            x0=e.bbox[0],
                                            y0=e.bbox[1],
                                            x1=e.bbox[2],
                                            y1=e.bbox[3],
                                            page=page_num,
                                            page_width=page_width,
                                            page_height=page_height,
                                        ),
                                        image=base64_string,
                                        image_mimetype=mime_type or "unknown",
                                        text="",
                                    )
                                )
        elements.extend(page_elements)
    return elements
Parse PDF and return a list of TextElement and ImageElement objects.
src/openparse/text/pdfminer/core.py