ExtractPDF4J¶
Extract tables from selectable text, ruled grids, and scanned PDFs in Java. Export the results to CSV or JSON, or work with the rows directly in your application.
Watch the four parsing demos¶
Each demo shows the source PDF, the CLI command, and rows from the generated CSV. Get the sample PDFs, expected CSVs, and commands on GitHub.
STREAM
Group selectable text into columns. The two-page example exports 29 transactions.
LATTICE
Follow visible grid lines to recover the cells of an invoice table.
OCRSTREAM
Use Tesseract to recognize text and recover columns from an image-only PDF.
HYBRID
Compare extraction strategies when you are unsure how the PDF represents its table.
Compare Java PDF tools¶
- ExtractPDF4J extracts structured tables from text-based and scanned PDFs using stream, lattice, OCR stream, and hybrid modes.
- Tabula Java extracts tables from text-based PDFs using stream and lattice modes. Tabula Java CLI and API
- Apache PDFBox creates, edits, renders, and extracts text from PDFs. ExtractPDF4J uses it for PDF processing. PDFBox features · Command-line tools
- Aspose.PDF for Java creates and edits PDFs and exposes table rows and cells through its
TableAbsorberAPI. Aspose.PDF for Java · Table extraction example
✓ means the named tool provides the feature directly. ✗ means the feature requires other tooling or custom code.
| Capability | ExtractPDF4J | Tabula Java | Apache PDFBox | Aspose.PDF for Java |
|---|---|---|---|---|
| Table extraction API | ✓ | ✓ | ✗ | ✓ |
| OCR to tables in one workflow | ✓ | ✗ | ✗ | ✗ |
| CLI exports tables to both CSV and JSON | ✓ | ✓ | ✗ | ✗ |
| General-purpose PDF creation and editing | ✗ | ✗ | ✓ | ✓ |
For image-only pages, Tabula requires a text layer from an OCR tool. PDFBox can render pages for an external OCR engine, and Aspose provides PDF recognition through a separate Aspose.OCR product. Tabula scan guidance · PDFBox rendering · Aspose.OCR for Java
Try the ExtractPDF4J parsing demos to see the sample inputs and generated outputs.
Use the Java API¶
Start with HybridParser when the layout is mixed or unknown.
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class QuickStart {
public static void main(String[] args) throws Exception {
List<Table> tables = new HybridParser("sample.pdf")
.pages("all")
.dpi(300f)
.parse();
if (!tables.isEmpty()) {
System.out.println(tables.get(0).toCSV(','));
}
}
}
See the Java quickstart, installation guide, or CLI reference to run your first extraction.
Contribute¶
If ExtractPDF4J helps you, star the project so more Java developers can find it. Open an issue to share a bug or an idea, or fork the repository and follow the contributing guide.