rhysleesltd/laravel-camelot

PHP Wrapper library for interfacing with the Camelot PDF table extraction library built in Python

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/rhysleesltd/laravel-camelot

v0.1 2026-01-31 14:48 UTC

This package is not auto-updated.

Last update: 2026-02-01 13:08:44 UTC


README

A Laravel wrapper for Camelot—the Python PDF table extraction library. Extract tabular data from PDFs in your Laravel app using the same API as the Camelot CLI, with Laravel helpers (e.g. Arr::, Collection::) and auto-discovered service provider.

Installation

You need both the PHP package and the Python Camelot library (this package calls the Camelot CLI under the hood).

1. PHP package (Laravel)

composer require rhysleesltd/laravel-camelot

The CamelotServiceProvider is auto-discovered; no manual registration is required.

2. Python Camelot

Install Camelot so the camelot command is available on your system path. Full details: Camelot installation docs.

Linux (Ubuntu / Debian)

# Optional: Ghostscript (only if you need a backend other than pdfium)
sudo apt install ghostscript

# Install Camelot (pdfium is the default backend as of v1.0.0)
pip install "camelot-py[base]"

Or with conda: conda install -c conda-forge camelot-py.

macOS

# Optional: Ghostscript (only if you need a backend other than pdfium)
brew install ghostscript

# Install Camelot
pip install "camelot-py[base]"

If the Ghostscript library is not found, you may need to symlink it (see the Camelot dependency docs).

Windows

pip install "camelot-py[base]"

For optional Ghostscript, use the Ghostscript Windows installer. For Tkinter (e.g. for plot), you may need ActiveTcl. See Camelot dependencies for details.

Verify the CLI works: camelot --help

Usage

The package adheres closely with the camelot CLI API Usage. Default output is in CSV format as a simple string. If you need to parse CSV strings we recommend the league/csv package (https://csv.thephpleague.com/)

<?php

use RhysLeesLtd\Camelot\Camelot;
use League\Csv\Reader;

$tables = Camelot::lattice('/path/to/my/file.pdf')
       ->extract();

$csv = Reader::createFromString($tables[0]);
$allRecords = $csv->getRecords();

Advanced Processing

Saving / Extracting

Note: No Camelot operations are run until one of these methods is run

$camelot->extract(); // uses temporary files and automatically grabs the table contents for you from each
$camelot->save('/path/to/my-file.csv'); // mirrors the behaviour of Camelot and saves files in the format /path/to/my-file-page-*-table-*.csv
$camelot->plot(); // useful for debugging, it will plot it in a separate window (see Visual Debugging below)   
Set Format
$camelot->json();
$camelot->csv();
$camelot->html();
$camelot->excel();
$camelot->sqlite();
Specify Page Numbers

$camelot->pages('1,2,3-4,8-end')

Reading encrypted PDFs

$camelot->password('my-pass')

Processing background lines

$camelot->stream()->processBackgroundLines()

Visual debugging

$camelot->plot()

Specify table areas
<?php

use RhysLeesLtd\Camelot\Camelot;
use RhysLeesLtd\Camelot\Areas;

Camelot::stream('my-file.pdf')
    ->inAreas(
        Areas::from($xTopLeft, $yTopLeft, $xBottomRight, $yBottomRight)
            // ->add($xTopLeft2, $yTopLeft2, $xBottomRight2, $yBottomRight2)
            // ->add($xTopLeft3, $yTopLeft3, $xBottomRight3, $yBottomRight3)
    );
Specify table regions
<?php

use RhysLeesLtd\Camelot\Camelot;
use RhysLeesLtd\Camelot\Areas;

Camelot::stream('my-file.pdf')
    ->inRegions(
        Areas::from($xTopLeft, $yTopLeft, $xBottomRight, $yBottomRight)
            // ->add($xTopLeft2, $yTopLeft2, $xBottomRight2, $yBottomRight2)
            // ->add($xTopLeft3, $yTopLeft3, $xBottomRight3, $yBottomRight3)
    );
Specify column separators

$camelot->stream()->setColumnSeparators($x1,$x2...)

Split text along separators

$camelot->split()

Flag superscripts and subscripts

$camelot->flagSize()

Strip characters from text

$camelot->strip("\n")

Improve guessed table areas

$camelot->setEdgeTolerance(500)

Improve guessed table rows

$camelot->setRowTolerance(15)

Detect short lines

$camelot->lineScale(20)

Shift text in spanning cells

$camelot->shiftText('r', 'b')

Copy text in spanning cells

$camelot->copyTextSpanningCells('r', 'b')

Credits

This package is a Laravel-oriented fork of the original PHP wrappers for Camelot. Thanks to:

The underlying table extraction is done by Camelot (Python). You need Camelot installed and available on your system path.

License

MIT. Use at your own risk, we accept no liability for how this code is used.