Government data, financial reports, academic papers, and legal documents are frequently published as PDFs rather than web pages. Extracting data from a PDF requires either parsing the PDF's internal content stream (which encodes text, fonts, and layout) or rendering the PDF to an image and applying OCR.
Libraries such as pdfplumber, PyPDF2, and Apache PDFBox can extract text from PDFs that contain embedded text objects. However, many scanned documents or image-only PDFs lack embedded text; these require OCR (optical character recognition) using tools like Tesseract or cloud vision APIs to recover the underlying content.
Table extraction from PDFs is particularly challenging because PDFs encode tables as positioned text objects rather than structured table elements. Specialised libraries use spatial analysis — grouping text objects by their X/Y coordinates — to reconstruct tabular structure.