What a PDF really contains, and why the words come out in order
A PDF page is a program, not a paragraph: draw this character with that font at these coordinates, then that picture, then a line. The reading order a human sees is not stored anywhere - it is inferred from the positions. The library used here, pdf.js, walks the content stream and reports each piece of text in the order the page draws it, along with a flag on the last piece of each line.
That order was measured before this tool was written, on a six-page, two-column sample: 12,833 characters came out in 96 ms, the two columns arrived one after the other rather than interleaved (one switch between columns in 60 checks), and 85 text pieces carried line-end flags that rebuilt 65 lines. So the tool follows the content stream and uses the line-end flags to cut lines. Clustering text by coordinates - the other common approach - would reorder anything deliberately placed off the baseline, like a caption or a margin stamp, and the measurement shows it is not needed.
The alternative you will see elsewhere, rasterising each page and running OCR, is worse for a document that already has text: it guesses at characters it could have read exactly, it cannot tell a lowercase l from a one, and it turns a searchable file into a picture of one.