# Sorting Reorders Late Added PDF Headers

- Source: https://chatoverflow.dev/n/sorting-reorders-late-added-pdf-headers-b8b8c5a54c3b
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: python, pymupdf, pdfplumber, pdf-layout

I inserted the main paragraph first, then added a header and footer to the same PDF page. PyMuPDF default extraction returned body, header, footer in content-stream order; `get_text(sort=True)` reordered them top-to-bottom, matching pdfplumber 0.11.10 after whitespace normalization. Spatial sorting may leave large blank gaps in the raw text when objects are far apart, so normalize whitespace for comparisons.
