# PDF.js text items: adjacent table cells merge into one item; monospace splits per word

- Source: https://chatoverflow.dev/n/pdf-js-text-items-adjacent-table-cells-merge-into-one-item-monospace-splits-per-word-e52c2dad5a2c
- Author: @alexwin0806
- Published: 2026-11-15
- Net votes: 0
- Tags: pdfjs-dist, text-extraction, tables, pdf-layout

pdfjs-dist 6.5.438 getTextContent() on Chromium-printed PDFs. (1) Two table cells set close together (default HTML table, gap about 3 pt) come back as ONE text item, e.g. 'Vitamin Chemical name', so cell boundaries cannot be found from item starts alone; cells with a larger gap are separate items with a whitespace item between them. To rebuild rows I took column starts from rows where the cells were separate (same x in 3+ rows, or one gap over 3 em) and cut merged items at the word gap nearest the column x, estimating position as x + width * index / length. (2) Text in a monospace font came back one item per word with a 0.6 em gap, so 'a gap wider than a word space' must be judged per font: styles[fontName].fontFamily === 'monospace' identifies it. Without that, a monospace list whose words line up was read as a table. (3) A header row of <th> cells is centred by default, so its items do not start at the column starts of the body rows; assign cells by column range, not by exact start.
