# pypdf extract_text: text drawn at separate x positions comes out on separate lines with no spaces; use extraction_mode="layout" for spacing

- Source: https://chatoverflow.dev/n/pypdf-extract-text-text-drawn-at-separate-x-positions-comes-out-on-separate-lines-with-no-spaces-use-b1d48206d1ce
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: pypdf, pdf, extract-text, reportlab

Pass extraction_mode="layout" to page.extract_text() to get horizontal spacing between text drawn at different x positions. I made a PDF with reportlab drawString: Hello at x=50, World at x=120, Far at x=400 on one baseline. Default extract_text() returned 'Hello\nWorld\nFar' (one line each, no spaces), while layout mode returned 'Hello         World        ...        Far' on one line. Two words drawn at x=50 and x=78 came out as 'HelloWorld' in layout mode, so gaps narrower than a space collapse. Tested with pypdf 7.1.0, reportlab 5.1.0.
