DEV Community

IronSoftware
IronSoftware

Posted on

PDF Text Line by Line in Python: pdfplumber and IronPDF

A card statement is a short PDF with a strict shape. The November 2026 statement in our test set has a heading, an account line, five transaction rows that each read as a date, a merchant and an amount, and a payment due date at the foot. A finance service reads each row, checks the total and then files a one-page reconciliation note, which is itself a PDF.

We read that statement line by line with pdfplumber 0.11.11 and with IronPDF for Python 2026.12.0.1 on 3 December 2026, and then produced the note. Reading went well in both, and the note is where the two routes separate.

What pdfplumber returns for each line

The library returns a dictionary per line, with the text and its position. The extract_text_lines method groups the page's characters into lines and, with return_chars=False, leaves out the character records that otherwise come with each line.

import pdfplumber

# Open the statement and take its first page
with pdfplumber.open("card-statement-2026-11.pdf") as statement:
    page = statement.pages[0]

    # Print each line with its distance from the top of the page
    for line in page.extract_text_lines(return_chars=False):
        print(round(line["top"]), line["text"])
Enter fullscreen mode Exit fullscreen mode

On the test statement it printed eight lines, from 78 Card statement November 2026 to 244 Payment due 15 December 2026, with the five transactions in between, such as 153 05 Nov Lisbon Rail Tickets 62.15. The vertical positions make it simple to keep only the rows inside the transactions table.

Parsing and filing with IronPDF for Python

Here the page comes back as one string, and the same package then renders the reconciliation note from HTML. Page numbers in ExtractTextFromPage start at zero, and a locked statement opens by passing its password to PdfDocument.FromFile after the path.

import re
from ironpdf import *

# Open the statement and split the first page's text into lines
statement = PdfDocument.FromFile("card-statement-2026-11.pdf")
lines = statement.ExtractTextFromPage(0).splitlines()

# Keep the lines that start with a date and end with an amount
rows = [line for line in lines if re.match(r"\d{2} [A-Z][a-z]{2} .+ \d+\.\d{2}$", line)]
total = sum(float(row.rsplit(" ", 1)[1]) for row in rows)

# Render the reconciliation note from the parsed rows and save it
note = ChromePdfRenderer().RenderHtmlAsPdf(f"<h1>November 2026</h1><p>{len(rows)} card transactions, total {total:.2f}</p>")
note.SaveAs("reconciliation-2026-11.pdf")
print(len(rows), f"{total:.2f}")
Enter fullscreen mode Exit fullscreen mode

The listing printed 5 381.35, and the saved note read back as 5 card transactions, total 381.35. The page text came out in reading order, one transaction per line, so the regular expression matched all five rows without any tolerance settings. A real note can carry the matched rows as an HTML table, a header with the account number and the finance team's styling, all rendered as in the IronPDF for Python HTML rendering example.

Why does the pdfplumber route need a second library?

Reading with pdfplumber ends before the note. The project's README lists what the library does not provide, and PDF generation, PDF modification and optical character recognition are on that list. A service built on pdfplumber therefore adds a second PDF library for the reconciliation note, with its own API, its own release cycle and its own dependency review.

Line grouping also deserves attention on each new layout. By default, extract_text starts a new line where the vertical position of one character differs from the next by more than y_tolerance, which is 3 points, and inserts a space where the horizontal gap exceeds x_tolerance, also 3. The README marks extract_text_lines, search and layout=True as experimental, so a pre-move check records the pdfplumber version each parser is pinned to and the sample statements it was last tested against.

Coordinates, search and tables in pdfplumber

Positional detail is its strength. Every character, word and line carries coordinates, and crop and within_bbox cut a page down to the transactions table before any text is read. The extract_words method returns each word with its bounding box, and search takes a regular expression, such as an amount pattern, and reports where each match sits on the page.

Table extraction runs on strategies such as lines and text with tunable tolerances, and visual debugging draws what the library found over a rendered page, which shortens the search for a misread row. The command-line tool writes each page's objects to CSV or JSON, pdfplumber.open takes a password argument, and the project is tested on Python 3.10 through 3.14.

Statement jobs in migration order

  • Jobs that read a statement and then produce a PDF of their own, such as reconciliation notes or exception reports.
  • Jobs that fill or stamp an existing PDF after parsing it, since modification is outside pdfplumber's scope.
  • Read-only jobs with stable layouts, once the services that write PDFs share one package.

We ran both listings on 3 December 2026 against the same five-row statement, on Python 3.13 under Windows 11, and IronPDF for Python read every transaction and wrote the reconciliation note in the same script. Processing a full month of real statements needs only a key issued through the IronPDF for Python licensing page.

pdfplumber, Python and Windows are trademarks or works of their respective owners, we have no affiliation with any of them, and the facts above are based on the pdfplumber README and changelog, our own runs and IronPDF for Python documentation.

Top comments (0)