pdfium and pypdf extract different text from the same PDF — what developers must know
Two widely used Python PDF libraries, pdfium and pypdf, can produce different text output from the same PDF file, posing risks for AI pipelines that rely on a single extractor. A developer investigation identified four specific mismatches: zero horizontal scaling text, ActualText substitutions, remapped Unicode tables, and uninvoked Form XObjects. Neither library is technically wrong, as all behaviors fall within the PDF specification, but each silently omits or alters characters the other captures. The discrepancies become particularly problematic when PDF text is fed directly to a large language model, since the model receives an incomplete or subtly altered version of the document. The author recommends running both extractors in parallel, normalizing their outputs, and treating any differences as a signal for potentially hidden or manipulated text.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in