# PDFLayoutTextStripper: pulling tables out of a PDF as text

> PDFLayoutTextStripper is a single class Apache-2.0 licensed Java library that extends the PDFTextStripper class from Apache PDFBox so that a PDF can be converted to text while keeping the original page layout. It is aimed at extracting tables and forms, and it is a small project whose documentation and release history have drifted apart.

**JonathanLink/PDFLayoutTextStripper** — Converts a pdf file into a text file while keeping the layout of the original pdf. Useful to extract the content from a table in a pdf file for instance. This is a subclass of PDFTextStripper class (from the Apache PDFBox library).

- Repository: https://github.com/JonathanLink/PDFLayoutTextStripper
- Website: https://jonathanlink.ch/PDFLayoutTextStripper.html
- Stars: 1,612 · Forks: 213
- Language: Java
- License: Apache-2.0
- Published: 2026-10-20 · Updated: 2026-10-20 · Language: en
- Canonical page: https://hysenlabs.com/projects/jonathanlink-pdflayouttextstripper

## The problem: a PDF table that turns into unreadable text

Most PDF text extraction works well when a document is a column of prose. It falls apart on a table, because a table is not a sequence of sentences but a grid of positions, and a plain text dump loses the information about which cell a value belongs to. PDFLayoutTextStripper exists for exactly that case. The project describes it as a way to convert a PDF file into a text file while keeping the layout of the original PDF, and the two use cases it names are extracting the content of a table in a PDF and extracting the content of a form. The audience is narrow and specific: a Java developer with a pile of PDFs whose tabular content has to end up in a spreadsheet, a database or a text pipeline. The value is not in PDF parsing, which PDFBox already does, but in how the extracted characters are placed on the page.

## One subclass of PDFTextStripper, not a second PDF parser

The architectural decision is visible in the first line of the description: PDFLayoutTextStripper is a subclass of the PDFTextStripper class from the Apache PDFBox library. That matters for adoption, because it means the project inherits PDFBox's document model, its PDFParser and its RandomAccessFile handling, and adds only the part that is missing. You are not signing up for a competing parser with its own object model, you are adding a class to an existing PDFBox pipeline. The sample code makes the flow plain: open the file with a RandomAccessFile, wrap it in a PDFParser, parse it, build a PDDocument from the parsed document, then instantiate PDFLayoutTextStripper and ask it for the text of the whole document. Everything except the last two lines would look identical in a plain PDFBox program, and the same structure means the class can be dropped into code that already parses PDFs.

## The Maven coordinates in the documentation point at an older release

The install instructions give a standard Maven dependency:

```xml
<dependency>
  <groupId>io.github.jonathanlink</groupId>
  <artifactId>PDFLayoutTextStripper</artifactId>
  <version>2.2.3</version>
</dependency>
```

That version number is the first thing to notice. The release history of the project shows v2.2.5 published on 2021-09-07, v2.2.4 on 2021-09-06 and v2.2.3 on 2018-12-11, so the snippet in the documentation is two releases behind what has actually been published. The Maven route is the one the documentation spells out for a Java project, and io.github.jonathanlink is the group id that dependency declares. Before pinning a version, pick it deliberately: 2.2.3 in the documentation, or one of the later tags, and check which one your build can actually resolve.

## Running it from a plain javac and java command

The project also documents a manual route that avoids Maven entirely, which is useful for a one-off extraction on a machine where you do not want to set up a build. On Linux and Mac the sequence is:

```bash
cd PDFLayoutTextStripper
javac -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar *.java
java -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar test
```

The three jars are PDFBox itself, commons-logging and fontbox, and the fontbox jar is picked up from inside the cloned project directory. The documentation warns that only PDFBox versions from 2.0.0 upwards are compatible with this version of PDFLayoutTextStripper, so the 2.0.6 jars in the example are the floor rather than the target. On Windows the same two commands apply with the classpath separator replaced by a semicolon instead of a colon. The class file that is compiled is test.java from the top of the repository, which is the sample program shown in the next section.

## The sample program, and the paired sample PDFs in the repository

The example file test.java is the shortest possible demonstration of the class, and it doubles as the manual run target:

```java
PDFParser pdfParser = new PDFParser(new RandomAccessFile(new File("./samples/bus.pdf"), "r"));
pdfParser.parse();
PDDocument pdDocument = new PDDocument(pdfParser.getDocument());
PDFTextStripper pdfTextStripper = new PDFLayoutTextStripper();
string = pdfTextStripper.getText(pdDocument);
```

The only line that differs from an ordinary PDFBox program is the instantiation, where PDFTextStripper becomes PDFLayoutTextStripper and the result is printed to standard output. The repository ships the inputs and the expected outputs side by side, with samples/bus.pdf and samples/bus.txt for the table case and samples/form.pdf and samples/form.txt for the form case, plus the two sample.png images in the README that show the before and after. Those pairs are the fastest way to judge the quality of the layout for your own documents, since you can diff your output against a known result instead of guessing. The class does not write a file in this example, it returns a string, so redirecting standard output or calling getText yourself are both reasonable.

## What the project does not say, and where that leaves you

Several things a buyer would ask about are simply not in the documentation, and it is worth naming them rather than assuming. There is no mention of scanned documents, image recognition or any form of OCR, so if your PDFs contain only page images there is no indication here that text will appear at all. There is no documented API for choosing a page range, setting a sort tolerance, or writing directly to a file, and the class exposes the text of a whole document in the one example given. There is also no statement about how the class handles rotated pages, multi column layouts or charts, which are exactly the cases where a layout aware stripper either helps or falls short. The practical approach is empirical: run the class over a document that resembles your worst case, then compare the output with the paired samples shipped in the repository before committing to it for a pipeline.

## Two other ways to reach the same text, and how they differ

The first alternative is to use the PDFTextStripper class from PDFBox directly and accept the output in content stream order. That removes the extra dependency entirely and is the right choice when your consumer is a language model, a search index or a human reading plain paragraphs, because column and row alignment carry no information for those consumers. PDFLayoutTextStripper differs precisely in where the characters are placed, which is what makes the table output usable. The second alternative is the commercial route the project itself points at, Spire.PDF for Java, described in the README as a library that can create, edit, convert and process PDF documents programmatically, with support for tables, forms, images and annotations. The difference in approach is scope: a commercial library covers the whole document lifecycle and adds licence cost, while this subclass covers one narrow extraction problem and depends on PDFBox.

## Conclusion

PDFLayoutTextStripper suits Java developers who need table or form content out of a PDF and can live with one small class and a PDFBox dependency, particularly for one-off extraction scripts and pipelines that post-process the text. It does not suit projects that need a maintained commercial component, teams that want an actively versioned library, or anyone expecting the project documentation to describe the newest artifact. Verify three things before adopting it: whether the text version you want on Maven Central is the 2.2.3 shown in the documentation or the later v2.2.5 tag, whether your PDFBox version is 2.0.0 or above, and whether the output layout is good enough for your parser by running the class over one of the sample PDFs in the samples directory. The last push was on 2026-10-18, while the most recent release tag, v2.2.5, dates from 2021-09-07.

## FAQ

### Which PDFBox versions are compatible with PDFLayoutTextStripper?

The documentation warns that only PDFBox versions from version 2.0.0 upwards are compatible with this version of PDFLayoutTextStripper.java, and the manual instructions use pdfbox-2.0.6.jar together with commons-logging-1.2.jar and fontbox-2.0.6.jar.

### How do I add PDFLayoutTextStripper to a Maven project?

The documented coordinates are groupId io.github.jonathanlink, artifactId PDFLayoutTextStripper and version 2.2.3. The release history goes further, with v2.2.4 and v2.2.5 published in September 2021, so the version in the documentation is behind the latest tag.

### Does PDFLayoutTextStripper handle scanned or image-only PDFs?

The documentation does not mention scanned pages, image recognition or OCR at all. Test it against one of the sample pairs in the samples directory, such as samples/bus.pdf with samples/bus.txt, before relying on it for image-only documents.

### What licence does PDFLayoutTextStripper use?

The project is distributed under the Apache-2.0 licence, and the LICENSE file at the top of the repository holds the full terms. The last push was on 2026-10-18, while the most recent release tag, v2.2.5, is dated 2021-09-07.

## Sources

- [JonathanLink/PDFLayoutTextStripper on GitHub](https://github.com/JonathanLink/PDFLayoutTextStripper)
- [License: Apache-2.0](https://github.com/JonathanLink/PDFLayoutTextStripper/blob/master/LICENSE)
- [Project website](https://jonathanlink.ch/PDFLayoutTextStripper.html)
- [README](https://github.com/JonathanLink/PDFLayoutTextStripper/blob/master/README.md)
- [Releases](https://github.com/JonathanLink/PDFLayoutTextStripper/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/jonathanlink-pdflayouttextstripper
