### Full Extraction Example
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
A complete example demonstrating parser initialization, configuration, execution, and iteration over extracted tables.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class ExtractorExample {
public static void main(String[] args) throws Exception {
List
tables = new HybridParser("statement.pdf")
.pages("1-3")
.dpi(300f)
.parse();
for (Table table : tables) {
System.out.println(table.toCSV(','));
}
}
}
```
--------------------------------
### Full-document hybrid extraction example
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Example command for full-document extraction using hybrid mode.
```bash
java -jar extractpdf4j-parser-.jar statement.pdf \
--mode hybrid \
--pages all \
--dpi 400 \
--out tables.csv
```
--------------------------------
### Install MkDocs Material
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Installs MkDocs Material and its dependencies from the requirements file. Ensure Python 3.9+ and pip are installed.
```bash
pip install -r docs/requirements.txt
```
--------------------------------
### Serve Docs Locally
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Starts a local web server to preview the documentation. Accessible at http://127.0.0.1:8000.
```bash
mkdocs serve
```
--------------------------------
### Quick Start with HybridParser
Source: https://extractpdf4j.github.io/ExtractPDF4J
Use HybridParser as a safe default for mixed or unknown PDF inputs. This example demonstrates parsing all pages of a PDF and printing the first extracted table as CSV.
```java
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 tables = new HybridParser("sample.pdf")
.pages("all")
.dpi(300f)
.parse();
if (!tables.isEmpty()) {
System.out.println(tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### Build Documentation Locally
Source: https://extractpdf4j.github.io/ExtractPDF4J/installation
Install Python dependencies and build the documentation locally using mkdocs. Ensure you have the required packages listed in docs/requirements.txt.
```bash
pip install -r docs/requirements.txt
mkdocs build --strict
```
--------------------------------
### Initialize and execute HybridParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/how-it-works/hybrid
Demonstrates the basic setup for parsing a PDF using the HybridParser, including page selection and DPI configuration.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class HybridExample {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("mixed.pdf")
.pages("all")
.dpi(300f)
.parse();
System.out.println("Tables found: " + tables.size());
}
}
```
--------------------------------
### CI Install Docs Dependencies
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Installs documentation dependencies within the CI environment. This ensures the build process uses the same libraries locally and in CI.
```yaml
- name: Install docs dependencies
run: pip install -r docs/requirements.txt
```
--------------------------------
### Configure page selection syntax
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/page-ranges
Examples of valid string formats for the .pages() method to define document subsets.
```text
.pages("1")
```
```text
.pages("1-3")
```
```text
.pages("1,3-5")
```
```text
.pages("all")
```
--------------------------------
### Hybrid Parser Quickstart
Source: https://extractpdf4j.github.io/ExtractPDF4J/quickstart
Use the HybridParser for a default entry point that handles both text-based and scanned PDFs. It's recommended for unknown input and mixed batches.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class HybridQuickStart {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("samples/mixed.pdf")
.pages("all")
.dpi(300f)
.parse();
if (!tables.isEmpty()) {
System.out.println(tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### OCR-focused tuning
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Example of an OcrStreamParser execution configured for all pages.
```java
new OcrStreamParser("archive_scan.pdf")
.pages("all")
.dpi(400f)
.parse();
```
--------------------------------
### Initialize HybridParser for PDF extraction
Source: https://extractpdf4j.github.io/ExtractPDF4J/getting-started
Demonstrates the basic setup for extracting tables from a PDF using the HybridParser. Requires the sample.pdf file to be present in the working directory.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class FirstRun {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("sample.pdf")
.pages("all")
.dpi(300f)
.parse();
System.out.println("Tables found: " + tables.size());
}
}
```
--------------------------------
### Scanned PDF extraction example
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Example command for extracting tables from a scanned PDF using lattice mode.
```bash
java -jar extractpdf4j-parser-.jar scan.pdf \
--mode lattice \
--pages 1 \
--dpi 450 \
--ocr cli \
--debug \
--keep-cells \
--debug-dir debug_out \
--out p1.csv
```
--------------------------------
### CI Setup Python
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Configures the Python environment for CI builds. Uses GitHub Actions to set up a specific Python version.
```yaml
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
```
--------------------------------
### Lattice Parser Quickstart
Source: https://extractpdf4j.github.io/ExtractPDF4J/quickstart
Use the LatticeParser when tables have clearly visible borders, like boxed or scanned tables with lines. Debug output is useful for unclear layouts.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.LatticeParser;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class LatticeQuickStart {
public static void main(String[] args) throws Exception {
List tables = new LatticeParser("samples/scanned.pdf")
.dpi(300f)
.keepCells(true)
.debug(true)
.debugDir(new File("out/debug"))
.pages("all")
.parse();
Files.createDirectories(Path.of("out"));
for (int i = 0; i < tables.size(); i++) {
Files.writeString(Path.of("out/lattice_table_" + i + ".csv"), tables.get(i).toCSV(','));
}
}
}
```
--------------------------------
### Lattice-focused tuning
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Example of a LatticeParser execution with debug mode enabled for troubleshooting.
```java
new LatticeParser("invoice.pdf")
.pages("1")
.dpi(300f)
.debug(true)
.keepCells(true)
.parse();
```
--------------------------------
### Instantiate PdfExtractService
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/microservice/extractpdf4j/service/PdfExtractService.html
Default constructor for PdfExtractService. No specific setup is required.
```java
public PdfExtractService()
```
--------------------------------
### Stream-focused tuning
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Example of a targeted StreamParser execution for specific pages.
```java
new StreamParser("report.pdf")
.pages("2-4")
.parse();
```
--------------------------------
### Stream Parser Quickstart
Source: https://extractpdf4j.github.io/ExtractPDF4J/quickstart
Use the StreamParser for text-based PDFs that have a usable text layer. Best for generated PDFs, statements, and text-layer reports.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.StreamParser;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class StreamQuickStart {
public static void main(String[] args) throws Exception {
List tables = new StreamParser("samples/statement.pdf")
.pages("1-3")
.parse();
if (!tables.isEmpty()) {
Files.createDirectories(Path.of("out"));
Files.writeString(Path.of("out/stream_table.csv"), tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### Batch Extraction Quickstart
Source: https://extractpdf4j.github.io/ExtractPDF4J/quickstart
Process multiple PDFs from a folder to CSV files using the HybridParser. This is useful for batch processing invoices or similar documents.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class BatchQuickStart {
public static void main(String[] args) throws Exception {
Files.createDirectories(Path.of("./out"));
for (File pdf : new File("./invoices").listFiles(f -> f.getName().endsWith(".pdf"))) {
List tables = new HybridParser(pdf.getPath())
.dpi(300f)
.parse();
if (!tables.isEmpty()) {
Files.writeString(
Path.of("./out/" + pdf.getName() + ".csv"),
tables.get(0).toCSV(',')
);
}
}
}
}
```
--------------------------------
### Hybrid default tuning
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Example of a standard HybridParser execution for unknown document inputs.
```java
new HybridParser("unknown.pdf")
.pages("all")
.dpi(300f)
.parse();
```
--------------------------------
### Write CSV to Disk
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Example of parsing a document and writing the first extracted table to a CSV file.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.StreamParser;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class CsvWriteExample {
public static void main(String[] args) throws Exception {
List tables = new StreamParser("report.pdf")
.pages("1")
.parse();
if (!tables.isEmpty()) {
Files.writeString(Path.of("out.csv"), tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### Main Class Constructor
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/cli/Main.html
The default constructor for the Main class. No specific setup or constraints are mentioned.
```java
public Main()
```
--------------------------------
### Handle Empty or Multiple Tables
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/models
Always handle cases where no tables are found, or when multiple tables are present in the document. This example iterates through all found tables and prints their CSV representation.
```java
if (tables.isEmpty()) {
System.out.println("No tables found.");
} else {
for (Table table : tables) {
System.out.println(table.toCSV(','));
}
}
```
--------------------------------
### OCR-Assisted Stream Parser Quickstart
Source: https://extractpdf4j.github.io/ExtractPDF4J/quickstart
Use the OcrStreamParser when the text layer in a PDF is weak or missing, aiding OCR recovery. Best for scanned statements and image-heavy PDFs.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.OcrStreamParser;
import java.util.List;
public class OcrQuickStart {
public static void main(String[] args) throws Exception {
List tables = new OcrStreamParser("samples/scan.pdf")
.pages("1-2")
.dpi(300f)
.parse();
System.out.println("Tables found: " + tables.size());
}
}
```
--------------------------------
### Correcting common syntax errors
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/page-ranges
Examples of invalid syntax versus the corrected versions for page selection.
```text
.pages("page 1")
```
```text
.pages("1")
```
```text
.pages("1 3-5")
```
```text
.pages("1,3-5")
```
--------------------------------
### Write Table to CSV file
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/models
This example demonstrates writing the CSV representation of the first table found in a PDF to a file named 'statement.csv'.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.StreamParser;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class TableCsvExample {
public static void main(String[] args) throws Exception {
List tables = new StreamParser("statement.pdf")
.pages("1")
.parse();
if (!tables.isEmpty()) {
Files.writeString(Path.of("statement.csv"), tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### Serve Documentation Locally
Source: https://extractpdf4j.github.io/ExtractPDF4J/installation
Preview the documentation locally by running the mkdocs serve command. This command builds and serves the documentation on a local development server.
```bash
mkdocs serve
```
--------------------------------
### Initialize HybridParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Create a new instance of the HybridParser by providing the path to the PDF file.
```java
new HybridParser("input.pdf")
```
--------------------------------
### GET /parsePage
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/StreamParser.html
Parses a specific page or the entire document from a file path.
```APIDOC
## GET /parsePage
### Description
Parses a single page or the entire document. Note: This method is deprecated; prefer using the parse(PDDocument) method for better performance.
### Method
GET
### Parameters
#### Query Parameters
- **page** (int) - Required - Page index to parse, or -1 to parse all pages.
### Response
#### Success Response (200)
- **List** - A list of Table objects extracted from the requested page(s).
```
--------------------------------
### LatticeParser Constructors
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/LatticeParser.html
Provides information on how to instantiate the LatticeParser.
```APIDOC
## LatticeParser()
### Description
Creates a `LatticeParser` for in-memory processing. The PDF document must be passed to the parse() method.
### Constructor
`LatticeParser()`
### Parameters
None
```
```APIDOC
## LatticeParser(String filepath)
### Description
Creates a `LatticeParser` instance associated with a specific file path.
### Constructor
`LatticeParser(String filepath)`
### Parameters
* **filepath** (String) - Required - The path to the PDF file.
```
--------------------------------
### Main Method - Program Entry Point
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/cli/Main.html
The main method serves as the program's entry point. It parses command-line arguments, initializes the appropriate parser, runs the extraction process, and handles writing or printing the CSV results. It throws an Exception for unrecoverable I/O errors.
```java
public static void main(String[] args) throws Exception
```
--------------------------------
### HybridParser Constructors
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/HybridParser.html
Details on how to instantiate the HybridParser.
```APIDOC
## Constructor Details
### HybridParser
public HybridParser(String filepath)
Creates a `HybridParser` for the given PDF file path.
Parameters:
`filepath` - path to the PDF file
### HybridParser
public HybridParser()
Creates a `HybridParser` for in-memory processing. The PDF document must be passed to the new parse() method.
```
--------------------------------
### Build Docs Locally
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Performs a strict build of the documentation, mirroring the CI environment. This ensures consistency between local builds and deployed versions.
```bash
mkdocs build --strict
```
--------------------------------
### Configure Parser Options
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Apply configuration methods like page range and DPI settings to a parser instance.
```java
new HybridParser("input.pdf")
.pages("1-3")
.dpi(300f)
```
--------------------------------
### Parse PDF and get tables
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/models
This is the main structure returned by parser operations. Use this pattern to parse a PDF and retrieve a list of extracted tables.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class ModelsExample {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("sample.pdf")
.pages("all")
.dpi(300f)
.parse();
if (!tables.isEmpty()) {
Table first = tables.get(0);
System.out.println(first.toCSV(','));
}
}
}
```
--------------------------------
### BaseParser Constructor Summary
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/BaseParser.html
Details the constructors available for creating BaseParser instances.
```APIDOC
## BaseParser Constructor Summary
### Constructors
- `protected BaseParser()` - Constructs a parser for in-memory processing.
- `protected BaseParser(String filepath)` - Constructs a parser for the given PDF file.
```
--------------------------------
### Basic CLI usage
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Standard command to run table extraction on a PDF file.
```bash
java -jar extractpdf4j-parser-.jar input.pdf \
--pages all \
--out tables.csv
```
--------------------------------
### LatticeParser Methods
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/LatticeParser.html
Details the methods available for configuring and using the LatticeParser.
```APIDOC
## debug(boolean on)
### Description
Toggle debug overlays/artifacts for visualization during parsing.
### Method
`debug`
### Parameters
* **on** (boolean) - Required - `true` to enable debug mode, `false` to disable.
```
```APIDOC
## debugDir(File dir)
### Description
Set the directory where debug artifacts will be saved.
### Method
`debugDir`
### Parameters
* **dir** (File) - Required - The directory to save debug artifacts.
```
```APIDOC
## dpi(float dpi)
### Description
Set the rasterization DPI (dots per inch) for rendering PDF pages to images.
### Method
`dpi`
### Parameters
* **dpi** (float) - Required - The DPI value for rasterization.
```
```APIDOC
## keepCells(boolean on)
### Description
Keep empty cells in the final grid. Useful for layouts with fixed structures.
### Method
`keepCells`
### Parameters
* **on** (boolean) - Required - `true` to keep empty cells, `false` to discard them.
```
```APIDOC
## parse(org.apache.pdfbox.pdmodel.PDDocument document)
### Description
Parses a previously loaded PDF document. This is the preferred method for in-memory processing.
### Method
`parse`
### Parameters
* **document** (org.apache.pdfbox.pdmodel.PDDocument) - Required - The PDDocument object to parse.
### Response
#### Success Response (200)
* **List** - A list of `Table` objects extracted from the document.
```
```APIDOC
## parsePage(int page)
### Description
Deprecated. Parses a single page or the entire document. This method loads the document from disk on every call. Prefer loading the PDDocument once and using `parse(PDDocument)`.
### Method
`parsePage`
### Parameters
* **page** (int) - Required - Page index to parse, or `-1` to parse all pages.
### Response
#### Success Response (200)
* **List** - A list of `Table` objects extracted from the requested page(s).
```
--------------------------------
### CI Build Docs
Source: https://extractpdf4j.github.io/ExtractPDF4J/docs-development
Executes a strict documentation build in the CI environment. This step is identical to the local strict build command.
```yaml
- name: Build docs
run: mkdocs build --strict
```
--------------------------------
### Parse Tables from PDF using StreamParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/how-it-works/stream
Use StreamParser to extract tables from specific pages of a text-based PDF. This example parses pages 1-3 of 'statement.pdf' and prints the first table as CSV.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.StreamParser;
import java.util.List;
public class StreamExample {
public static void main(String[] args) throws Exception {
List tables = new StreamParser("statement.pdf")
.pages("1-3")
.parse();
if (!tables.isEmpty()) {
System.out.println(tables.get(0).toCSV(','));
}
}
}
```
--------------------------------
### CSV Conversion and Writing
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Explains how to convert extracted tables to CSV format and write them to disk.
```APIDOC
## CSV conversion
Once a `Table` is returned, a common next step is converting it to CSV:
```java
table.toCSV(',')
```
This is useful for:
* quick inspection
* local validation
* downstream file generation
* pipeline handoff
## Writing CSV to disk
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.StreamParser;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public class CsvWriteExample {
public static void main(String[] args) throws Exception {
List tables = new StreamParser("report.pdf")
.pages("1")
.parse();
if (!tables.isEmpty()) {
Files.writeString(Path.of("out.csv"), tables.get(0).toCSV(','));
}
}
}
```
```
--------------------------------
### Initialize LatticeParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Use for documents containing ruled or grid-based tables with visible borders.
```java
import com.extractpdf4j.parsers.LatticeParser;
new LatticeParser("scan.pdf")
.pages("1")
.dpi(300f)
.keepCells(true)
.parse();
```
--------------------------------
### Initialize StreamParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Use for text-based PDFs where the text layer is natively accessible.
```java
import com.extractpdf4j.parsers.StreamParser;
new StreamParser("statement.pdf")
.pages("1-3")
.parse();
```
--------------------------------
### Initialize HybridParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Use as a general-purpose default for mixed document types or when the input structure is uncertain.
```java
import com.extractpdf4j.parsers.HybridParser;
new HybridParser("mixed.pdf")
.pages("all")
.dpi(300f)
.parse();
```
--------------------------------
### Main
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/allclasses-index.html
Main class for executing PDF extraction tasks.
```APIDOC
## Main
### Description
Main class for executing PDF extraction tasks.
### Method
N/A (Class description)
### Endpoint
N/A (Library class)
### Parameters
N/A (Class description)
### Request Example
N/A
### Response
N/A
```
--------------------------------
### LatticeParser Configuration Methods
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/class-use/LatticeParser.html
Methods for configuring the LatticeParser's behavior during PDF parsing.
```APIDOC
## LatticeParser Configuration Methods
### Description
Methods for configuring the LatticeParser's behavior during PDF parsing.
### Methods
#### `debug(boolean on)`
* **Description**: Toggle debug overlays/artifacts.
* **Parameters**:
* `on` (boolean) - Required - Whether to enable or disable debug mode.
#### `debugDir(File dir)`
* **Description**: Set debug artifact directory.
* **Parameters**:
* `dir` (File) - Required - The directory to store debug artifacts.
#### `dpi(float dpi)`
* **Description**: Set rasterization DPI.
* **Parameters**:
* `dpi` (float) - Required - The DPI value for rasterization.
#### `keepCells(boolean on)`
* **Description**: Keep empty cells in the final grid (useful for fixed layouts).
* **Parameters**:
* `on` (boolean) - Required - Whether to keep empty cells.
```
--------------------------------
### BaseParser Method Summary
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/BaseParser.html
Lists and describes the methods available in the BaseParser class, including parsing and configuration methods.
```APIDOC
## BaseParser Method Summary
### Methods
- `protected List finalizeResults(List tables, String sourcePath)` - Normalizes parser output for "no tables" situations.
- `BaseParser pages(String pages)` - Sets the pages to parse.
- `List parse()` - Parses the configured pages from the PDF file.
- `abstract List parse(org.apache.pdfbox.pdmodel.PDDocument document)` - Parses a previously loaded PDF document.
- `protected abstract List parsePage(int page)` - Parses a single page or the entire document.
- `BaseParser stripText(boolean strip)` - Enables or disables text normalization for stream-style extraction.
```
--------------------------------
### BaseParser Configuration and Parsing
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/BaseParser.html
Details on configuring and using the BaseParser for PDF table extraction.
```APIDOC
## BaseParser Configuration and Parsing
### Description
This section details the configuration options and parsing methods available in the `BaseParser` class for extracting tables from PDF documents.
### Fields
- **filepath** (String) - The path to the PDF file. Can be null for in-memory documents.
- **pages** (String) - Page selection string (e.g., "1", "2-5", "1,3-4", "all"). Defaults to "1".
- **stripText** (boolean) - Flag to normalize/strip text during stream-based extraction. Defaults to false.
### Constructors
- **BaseParser(String filepath)**: Constructs a parser for a given PDF file.
- **BaseParser()**: Constructs a parser for in-memory processing.
### Methods
- **pages(String pages)**: Sets the pages to parse. Returns the parser instance for chaining.
- **stripText(boolean strip)**: Enables or disables text normalization. Returns the parser instance for chaining.
- **parse()**: Parses the configured pages from the PDF file. Returns a list of `Table` instances.
- **parse(org.apache.pdfbox.pdmodel.PDDocument document)**: Parses a previously loaded PDF document. Returns a list of extracted tables.
### Protected Methods
- **parsePage(int page)**: Parses a single page or the entire document. Implementations must handle `page == -1` for all pages.
- **finalizeResults(List tables, String sourcePath)**: Normalizes parser output, ensuring a non-null list is returned.
### Throws
- **IOException**: If reading the file fails or a parsing error occurs during `parse()` or `parsePage()`.
```
--------------------------------
### OcrStreamParser Configuration and Parsing
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/OcrStreamParser.html
Methods for configuring the OcrStreamParser instance and executing the table extraction process.
```APIDOC
## OcrStreamParser Configuration
### Description
Configures the parser settings including DPI, debug modes, and required table headers before executing the parse operation.
### Methods
- **dpi(float dpi)**: Sets the DPI for OCR processing.
- **debug(boolean on)**: Enables or disables debug mode.
- **debugDir(File dir)**: Sets the directory for debug output.
- **requiredHeaders(List headers)**: Sets the headers used for column boundary anchoring.
## parse(PDDocument document)
### Description
Parses a previously loaded PDF document to extract tables.
### Parameters
- **document** (PDDocument) - Required - The PDF document to parse.
### Response
- **List** - A list of extracted Table objects.
```
--------------------------------
### Enable Debug Mode via CLI
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/debug-images
Uses command-line arguments to enable debug mode and specify the output directory for artifacts.
```bash
java -jar extractpdf4j-parser-.jar scanned.pdf \
--mode lattice \
--pages 1 \
--dpi 300 \
--debug \
--debug-dir out/debug \
--out page1.csv
```
--------------------------------
### Select OCR provider
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/ocr-tuning
Specifies the OCR engine provider for the CLI tool.
```bash
--ocr auto|cli|bytedeco
```
--------------------------------
### CLI Execution
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/cli/Main.html
The main entry point for the ExtractPDF4J CLI, allowing users to specify extraction modes, page ranges, and output configurations.
```APIDOC
## CLI Execution
### Description
Parses command-line flags, constructs the appropriate parser (stream, lattice, ocrstream, or hybrid), runs extraction, and writes CSV output to STDOUT or a file.
### Parameters
#### Command-line Arguments
- **pdf** (string) - Required - Path to the PDF file.
- **--mode** (string) - Optional - Extraction mode: stream, lattice, ocrstream, or hybrid.
- **--pages** (string) - Optional - Page range: "1", "2-5", "1,3-4", or "all".
- **--sep** (string) - Optional - CSV separator character.
- **--out** (string) - Optional - Output file path.
- **--debug** (flag) - Optional - Enables debug mode.
- **--dpi** (integer) - Optional - DPI setting for processing (default 300).
- **--ocr** (string) - Optional - OCR engine: auto, cli, or bytedeco.
- **--keep-cells** (flag) - Optional - Retains cell structure.
- **--debug-dir** (string) - Optional - Directory for debug output.
- **--min-score** (float) - Optional - Minimum score threshold (0-1).
- **--require-headers** (string) - Optional - Comma-separated list of required headers.
### Request Example
java -jar extractpdf4j-cli-1.0.0.jar document.pdf --mode lattice --pages 1-3 --out results.csv
```
--------------------------------
### Gradle Dependency Management with BOM
Source: https://extractpdf4j.github.io/ExtractPDF4J/installation
Use the ExtractPDF4J BOM in Gradle for simplified dependency management. Import the BOM and then declare the service module without a version.
```gradle
implementation platform("io.github.extractpdf4j:extractpdf4j-bom:2.1.0")
implementation "io.github.extractpdf4j:extractpdf4j-service"
```
--------------------------------
### BaseParser Class Overview
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/BaseParser.html
Provides an overview of the BaseParser class, its purpose, and known subclasses.
```APIDOC
## BaseParser Class
### Description
Abstract base for all PDF table parsers in `com.extractpdf4j`. Concrete implementations (e.g., `StreamParser`, `LatticeParser`, `OcrStreamParser`, `HybridParser`) should extend this class and implement `parsePage(int)`.
### Known Subclasses
- `HybridParser`
- `LatticeParser`
- `OcrStreamParser`
- `StreamParser`
```
--------------------------------
### Debug output configuration
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Flags for generating intermediate artifacts for troubleshooting.
```text
--debug
--debug-dir debug_out
```
--------------------------------
### HybridParser Methods
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/HybridParser.html
Lists and describes the methods available in the HybridParser class, including configuration and parsing methods.
```APIDOC
## HybridParser Methods
### Description
Details the instance methods of the `HybridParser` class used for configuration and initiating the parsing process.
### Method Summary
#### `debug(boolean on)`
- **Description**: Enables or disables debug outputs for lattice/OCR strategies.
- **Returns**: `HybridParser` (for chaining)
#### `debugDir(File dir)`
- **Description**: Sets the directory where debug artifacts (lattice + OCR) should be written.
- **Parameters**:
- **dir** (File) - Required - The directory for debug artifacts.
- **Returns**: `HybridParser` (for chaining)
#### `dpi(float dpi)`
- **Description**: Sets DPI for image-based parsing (used by lattice + OCR strategies).
- **Parameters**:
- **dpi** (float) - Required - The DPI value.
- **Returns**: `HybridParser` (for chaining)
#### `keepCells(boolean on)`
- **Description**: Determines whether to preserve empty cells when reconstructing grids (lattice only).
- **Parameters**:
- **on** (boolean) - Required - `true` to keep empty cells, `false` otherwise.
- **Returns**: `HybridParser` (for chaining)
#### `minScore(double score)`
- **Description**: Sets the minimum allowed average score across a list of tables.
- **Parameters**:
- **score** (double) - Required - The minimum score threshold.
- **Returns**: `HybridParser` (for chaining)
#### `pages(String pages)`
- **Description**: Sets the page selection for this parser and propagates the same selection to all underlying strategies.
- **Parameters**:
- **pages** (String) - Required - Page selection string (e.g., "all", "1", "2-5").
- **Returns**: `HybridParser` (for chaining)
#### `parse(org.apache.pdfbox.pdmodel.PDDocument document)`
- **Description**: Parses a previously loaded PDF document.
- **Parameters**:
- **document** (PDDocument) - Required - The PDF document to parse.
- **Returns**: `List` - A list of extracted tables.
#### `parsePage(int page)`
- **Description**: Runs stream, lattice, and OCR-backed stream for the requested page(s) and returns the best-scoring set of tables.
- **Parameters**:
- **page** (int) - Required - The page number to parse (or -1 for all pages).
- **Returns**: `List` - A list of extracted tables.
#### `stripText(boolean strip)`
- **Description**: Enables or disables text normalization for stream-style extraction across all underlying strategies.
- **Parameters**:
- **strip** (boolean) - Required - `true` to strip text, `false` otherwise.
- **Returns**: `HybridParser` (for chaining)
```
--------------------------------
### Initialize OcrStreamParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/parsers
Use for scanned or image-heavy PDFs that require OCR to recover text content.
```java
import com.extractpdf4j.parsers.OcrStreamParser;
new OcrStreamParser("scan.pdf")
.pages("1-2")
.dpi(400f)
.parse();
```
--------------------------------
### HybridParser Usage
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/HybridParser.html
Demonstrates how to use the HybridParser to extract tables from a PDF file, with options for setting DPI, debug mode, and page selection.
```APIDOC
## HybridParser Usage
### Description
This example shows how to instantiate and use the `HybridParser` to extract tables from a PDF. It includes optional configurations for DPI, debugging, and specifying which pages to parse.
### Method
```java
List tables = new HybridParser("path/to/file.pdf")
.dpi(300f) // optional, helps scans
.debug(true) // optional, write lattice/ocr debug artifacts
.pages("all") // "1", "2-5", "1,3-4", or "all"
.parse();
```
### Parameters
- **filepath** (String) - Constructor parameter: Path to the PDF file.
- **dpi** (float) - Optional: Sets the DPI for image-based parsing (used by lattice + OCR strategies).
- **debug** (boolean) - Optional: Enables or disables debug outputs for lattice/OCR strategies.
- **pages** (String) - Optional: Specifies the pages to parse. Accepts formats like "1", "2-5", "1,3-4", or "all".
### Request Example
```json
{
"filepath": "path/to/file.pdf",
"dpi": 300.0,
"debug": true,
"pages": "all"
}
```
### Response
#### Success Response (200)
- **tables** (List) - A list of extracted tables from the specified pages.
```
--------------------------------
### Page selection syntax
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Syntax for specifying which pages to process.
```text
--pages 1|all|1,3-5
```
--------------------------------
### ExtractPDF4J CLI Usage Synopsis
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/cli/Main.html
This is the command-line synopsis for the ExtractPDF4J tool. It outlines the required PDF file argument and various optional flags for controlling extraction mode, page selection, output file, separator, debugging, OCR settings, and more.
```bash
java -jar extractpdf4j-cli-1.0.0.jar
[--mode stream|lattice|ocrstream|hybrid]
[--pages 1|all|1,3-5]
[--sep ,]
[--out out.csv]
[--debug]
[--dpi 300]
[--ocr auto|cli|bytedeco]
[--keep-cells]
[--debug-dir ]
[--min-score 0-1]
[--require-headers Date,Description,Balance]
```
--------------------------------
### BaseParser Configuration Methods
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/class-use/BaseParser.html
Methods for configuring parsing behavior such as page selection and text normalization.
```APIDOC
## Method: BaseParser.pages
### Description
Sets the specific pages to be parsed.
### Parameters
- **pages** (String) - Required - A string representing the page range or selection.
### Response
- **BaseParser** (Object) - Returns the current parser instance for chaining.
## Method: BaseParser.stripText
### Description
Enables or disables text normalization for stream-style extraction.
### Parameters
- **strip** (boolean) - Required - True to enable text normalization, false to disable.
### Response
- **BaseParser** (Object) - Returns the current parser instance for chaining.
```
--------------------------------
### com.extractpdf4j.cli.Main
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/cli/package-summary.html
The primary entry point for the ExtractPDF4J command-line interface.
```APIDOC
## CLI Entry Point: com.extractpdf4j.cli.Main
### Description
The Main class serves as the primary execution point for the ExtractPDF4J command-line interface, enabling users to trigger PDF extraction workflows directly from the shell.
### Usage
Execute the class via the Java runtime to initiate the CLI workflow:
`java -cp extractpdf4j.jar com.extractpdf4j.cli.Main [arguments]`
```
--------------------------------
### Extract tables using CLI
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/page-ranges
Command line usage for specifying page ranges during document parsing.
```bash
java -jar extractpdf4j-parser-.jar statement.pdf \
--mode hybrid \
--pages 2-4 \
--out result.csv
```
--------------------------------
### Default CLI mode
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
The default extraction mode when no mode is specified.
```text
--mode hybrid
```
--------------------------------
### Perform OCR extraction in Java
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/ocr-tuning
Demonstrates using OcrStreamParser to extract tables from specific pages with a custom DPI setting.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.OcrStreamParser;
import java.util.List;
public class OcrTuningExample {
public static void main(String[] args) throws Exception {
List tables = new OcrStreamParser("scan.pdf")
.pages("1-2")
.dpi(400f)
.parse();
System.out.println("Tables found: " + tables.size());
}
}
```
--------------------------------
### Output file configuration
Source: https://extractpdf4j.github.io/ExtractPDF4J/cli
Specify the output file path for extracted tables.
```text
--out out.csv
```
--------------------------------
### Extract tables using Java API
Source: https://extractpdf4j.github.io/ExtractPDF4J/advanced-usage/page-ranges
Demonstrates applying page ranges within a Java application using the HybridParser.
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class PageRangesExample {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("statement.pdf")
.pages("2-4")
.dpi(300f)
.parse();
System.out.println("Tables found: " + tables.size());
}
}
```
--------------------------------
### Debug Output Configuration
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Enable debug mode to assist in troubleshooting extraction issues.
```java
.debug(true)
```
--------------------------------
### HybridParser Constructors
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/HybridParser.html
Details the available constructors for the HybridParser class.
```APIDOC
## HybridParser Constructors
### Description
Provides information on how to create instances of the `HybridParser` class.
### Constructor Summary
#### `HybridParser()`
- **Description**: Creates a `HybridParser` for in-memory processing.
#### `HybridParser(String filepath)`
- **Description**: Creates a `HybridParser` for the given PDF file path.
- **Parameters**:
- **filepath** (String) - Required - The path to the PDF file.
```
--------------------------------
### HybridParser Configuration Methods
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/class-use/HybridParser.html
These methods allow you to configure the behavior of the HybridParser for PDF extraction.
```APIDOC
## HybridParser Configuration Methods
### Description
Methods to configure debug output, DPI, cell preservation, minimum score, and text normalization for the HybridParser.
### Methods
#### `debug(boolean on)`
* **Description**: Enables or disables debug outputs for lattice/OCR strategies.
* **Parameters**:
* `on` (boolean) - Required - Whether to enable debug output.
#### `debugDir(File dir)`
* **Description**: Sets the directory where debug artifacts should be written (lattice + OCR).
* **Parameters**:
* `dir` (File) - Required - The directory for debug artifacts.
#### `dpi(float dpi)`
* **Description**: Sets the DPI for image-based parsing (used by lattice + OCR strategies).
* **Parameters**:
* `dpi` (float) - Required - The DPI value.
#### `keepCells(boolean on)`
* **Description**: Determines whether to preserve empty cells when reconstructing grids (lattice only).
* **Parameters**:
* `on` (boolean) - Required - Whether to keep empty cells.
#### `minScore(double score)`
* **Description**: Sets the minimum allowed average score across a list of tables.
* **Parameters**:
* `score` (double) - Required - The minimum score threshold.
#### `stripText(boolean strip)`
* **Description**: Enables or disables text normalization for stream-style extraction across all underlying strategies.
* **Parameters**:
* `strip` (boolean) - Required - Whether to strip text normalization.
```
--------------------------------
### static BaseParser parserFrom(Class> type, String filepath)
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/annotations/ExtractPdfAnnotations.html
Builds a parser instance from the ExtractPdfConfig annotation on a class, optionally specifying a file path.
```APIDOC
## static BaseParser parserFrom(Class> type, String filepath)
### Description
Builds a parser instance from the ExtractPdfConfig annotation on a class. If a filepath is provided, it associates the parser with that file; otherwise, it supports in-memory usage.
### Parameters
#### Path Parameters
- **type** (Class>) - Required - The annotated class containing ExtractPdfConfig.
- **filepath** (String) - Optional - The PDF file path (use null for in-memory usage).
### Response
- **BaseParser** - A configured parser instance.
### Errors
- **IllegalArgumentException** - Thrown if the provided class does not have the ExtractPdfConfig annotation.
```
--------------------------------
### Extractor Usage Pattern
Source: https://extractpdf4j.github.io/ExtractPDF4J/api/extractor
Demonstrates the typical workflow for using ExtractPDF4J parsers: instantiate, configure, parse, and process results.
```APIDOC
## Extractor Usage Pattern
This page covers the common parser usage pattern in ExtractPDF4J. Although there are multiple parser implementations, they are typically used in a similar way:
1. create a parser instance
2. configure extraction options
3. call `parse()`
4. work with the returned `List`
### Common construction pattern
A parser is generally created with a PDF path:
```java
new HybridParser("input.pdf")
```
Then you optionally add configuration:
```java
new HybridParser("input.pdf")
.pages("1-3")
.dpi(300f)
```
Then you call:
```java
.parse()
```
### Full example
```java
import com.extractpdf4j.helpers.Table;
import com.extractpdf4j.parsers.HybridParser;
import java.util.List;
public class ExtractorExample {
public static void main(String[] args) throws Exception {
List tables = new HybridParser("statement.pdf")
.pages("1-3")
.dpi(300f)
.parse();
for (Table table : tables) {
System.out.println(table.toCSV(','));
}
}
}
```
```
--------------------------------
### Render PDF Page
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/helpers/ImagePdfUtils.html
Renders a single PDF page to a BufferedImage at a specified DPI. The output is suitable for downstream line/edge detection.
```APIDOC
## renderPage
### Description
Renders a single PDF page to a `BufferedImage` at the requested DPI.
### Method
GET
### Endpoint
`/api/pdf/renderPage`
### Parameters
#### Query Parameters
- **doc** (PDDocument) - Required - An open `PDDocument` object.
- **pageIndexZero** (int) - Required - Zero-based page index (0 = first page).
- **dpi** (float) - Required - Dots per inch to render at (e.g., 300f for scans).
### Response
#### Success Response (200)
- **BufferedImage** (BufferedImage) - A binary `BufferedImage` of the page.
#### Response Example
```
// Example response would be a BufferedImage object, not directly representable in JSON.
```
### Throws
- **IOException** - if rendering fails
```
--------------------------------
### Gradle Dependency Declaration (Without BOM)
Source: https://extractpdf4j.github.io/ExtractPDF4J/installation
Declare core, service, and CLI modules directly in Gradle if not using the BOM. Specify the version for each dependency.
```gradle
implementation "io.github.extractpdf4j:extractpdf4j-core:2.1.0"
implementation "io.github.extractpdf4j:extractpdf4j-service:2.1.0"
implementation "io.github.extractpdf4j:extractpdf4j-cli:2.1.0"
```
--------------------------------
### static BaseParser parserFrom(Class> type)
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/annotations/ExtractPdfAnnotations.html
Builds a parser instance from the ExtractPdfConfig annotation on a class without a file path.
```APIDOC
## static BaseParser parserFrom(Class> type)
### Description
Builds a parser instance from the ExtractPdfConfig annotation on a class without specifying a file path.
### Parameters
#### Path Parameters
- **type** (Class>) - Required - The annotated class containing ExtractPdfConfig.
### Response
- **BaseParser** - A configured parser instance.
### Errors
- **IllegalArgumentException** - Thrown if the provided class does not have the ExtractPdfConfig annotation.
```
--------------------------------
### Debug PDF Extraction with LatticeParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/faq
Enable debug mode for LatticeParser to generate detailed artifacts for analysis. Specify the output directory for debug files. Recommended for troubleshooting extraction problems.
```java
new LatticeParser("scanned.pdf")
.pages("1")
.dpi(300f)
.debug(true)
.debugDir(new File("out/debug"))
.parse();
```
--------------------------------
### BaseParser Page Selection Contract
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/extractpdf4j/parsers/BaseParser.html
Explains the convention for handling page ranges, including the format and how special values like 'all' are interpreted.
```APIDOC
## BaseParser Page Selection Contract
### Description
Page ranges are provided as a human-friendly string via `pages(String)`. The format supports values such as `"1"`, `"2-5"`, `"1,3-4"`, and `"all"`. The helper `PageRange.parse(..)` converts this into a list of integers.
### Convention
- If `parsePage(-1)` is called, it indicates **all pages** should be parsed.
- Otherwise, `parsePage(p)` is called once per requested page number `p`.
```
--------------------------------
### LatticeParser
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/allclasses-index.html
A parser optimized for extracting data from lattice-like PDF structures.
```APIDOC
## LatticeParser
### Description
A parser optimized for extracting data from lattice-like PDF structures.
### Method
N/A (Class description)
### Endpoint
N/A (Library class)
### Parameters
N/A (Class description)
### Request Example
N/A
### Response
N/A
```
--------------------------------
### PdfExtractService Class Overview
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/microservice/extractpdf4j/service/package-tree.html
Overview of the PdfExtractService class structure and hierarchy.
```APIDOC
## Class: com.microservice.extractpdf4j.service.PdfExtractService
### Description
The PdfExtractService class is the core service component for handling PDF extraction tasks within the ExtractPDF4J library.
### Hierarchy
- java.lang.Object
- com.microservice.extractpdf4j.service.PdfExtractService
```
--------------------------------
### Main Class - ExtractPDF4j
Source: https://extractpdf4j.github.io/ExtractPDF4J/apidocs/com/microservice/extractpdf4j/Main.html
Documentation for the main entry point of the ExtractPDF4j application.
```APIDOC
## Main Class
### Description
This class serves as the main entry point for the ExtractPDF4j application. It is annotated with `@SpringBootApplication` to enable Spring Boot's auto-configuration and component scanning.
### Class Details
```java
@SpringBootApplication(scanBasePackages={"com.microservice.extractpdf4j","com.extractpdf4j"}) @EnableAsync
public class Main extends Object
```
### Constructor Summary
#### Main()
- **Description**: Default constructor for the Main class.
### Method Summary
#### main(String[] args)
- **Description**: The main method, which is the entry point for the application. It is a static method that accepts an array of strings as arguments.
- **Modifier**: `static void`
### Methods inherited from class java.lang.Object
- `clone`, `equals`, `finalize`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait`
```