def ingest(
    doc: Pdf,
) -> List[TextElement]:
    """Parses text elements from a given pdf document."""
    elements = []
    pdoc = doc.to_pymupdf_doc()
    for page_num, page in enumerate(pdoc):
        page_ocr = page.get_textpage_ocr(flags=0, full=False)
        for node in page.get_text("dict", textpage=page_ocr, sort=True)["blocks"]:
            if node["type"] != 0:
                continue

            lines = _lines_from_ocr_output(node["lines"])

            # Flip y-coordinates to match the top-left origin system
            fy0 = page.rect.height - node["bbox"][3]
            fy1 = page.rect.height - node["bbox"][1]

            elements.append(
                TextElement(
                    bbox=Bbox(
                        x0=node["bbox"][0],
                        y0=fy0,
                        x1=node["bbox"][2],
                        y1=fy1,
                        page=page_num,
                        page_width=page.rect.width,
                        page_height=page.rect.height,
                    ),
                    text="\n".join(line.text for line in lines),
                    lines=tuple(lines),
                )
            )
    return elements
Parses text elements from a given pdf document.
src/openparse/text/pymupdf/core.py