For scanned PDFs, pipe through ocrmypdf first (Pattern #11). Pattern #8: Table Extraction with Visual Debugging (pdfplumber + cv2) The Impact: pdfplumber’s .extract_table() works on 80% of PDFs. For the remaining 20%, you need to debug using bounding boxes.
def pdf_to_images_highres(pdf_path: str, dpi=300): zoom = dpi / 72 # PDF's base resolution is 72 DPI mat = fitz.Matrix(zoom, zoom) doc = fitz.open(pdf_path) images = [] for page in doc: pix = page.get_pixmap(matrix=mat, alpha=False) images.append(pix.tobytes("png")) doc.close() return images # use BytesIO to save as files Use in serverless functions; each page renders independently. Pattern #5: Intelligent Merging & Reordering (pypdf) The Impact: Merging dozens of PDFs for report generation? pypdf’s pure-python nature makes it reliable and memory-savvy. For scanned PDFs, pipe through ocrmypdf first (Pattern #11)
Use fitz.Document with page-level caching and structured block extraction. Use fitz