PHPackages                             ferdiunal/php-firepdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ferdiunal/php-firepdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ferdiunal/php-firepdf
=====================

PHP FFI wrapper for the Rust pdf-inspector library.

v0.1.0(1mo ago)5861[2 PRs](https://github.com/ferdiunal/php-firepdf/pulls)MITPHPPHP ^8.4CI passing

Since Apr 22Pushed 2w agoCompare

[ Source](https://github.com/ferdiunal/php-firepdf)[ Packagist](https://packagist.org/packages/ferdiunal/php-firepdf)[ Docs](https://github.com/ferdiunal/php-firepdf)[ GitHub Sponsors](https://github.com/ferdiunal)[ RSS](/packages/ferdiunal-php-firepdf/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (14)Versions (5)Used By (0)

php-firepdf
===========

[](#php-firepdf)

PHP FFI wrapper for [pdf-inspector](https://github.com/firecrawl/pdf-inspector), a fast Rust library for PDF classification and text extraction.

[![Latest Version on Packagist](https://camo.githubusercontent.com/c93819ca63b0c3b49f583b7aab98ba2d9306fc42ab93869f5133506d9fd00dfd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6665726469756e616c2f7068702d666972657064662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ferdiunal/php-firepdf)[![Total Downloads](https://camo.githubusercontent.com/00a28f560dd4ddd3f4c6856079426d6567c8f9f8fe281d4f527ad1753f83f818/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6665726469756e616c2f7068702d666972657064662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ferdiunal/php-firepdf)

Documentation: **English** | [Türkçe](README.TR.md)

This package exposes the full pdf-inspector API surface (process, detect, classify, extract text, region extraction, per-page markdown) through PHP FFI. It includes a Laravel service provider and facade for seamless integration.

Requirements
------------

[](#requirements)

- PHP 8.4+
- PHP FFI extension enabled (`extension=ffi`)
- Rust toolchain (only needed when you build native binaries yourself)

Installation
------------

[](#installation)

```
composer require ferdiunal/php-firepdf
```

### Native Library Resolution (Production)

[](#native-library-resolution-production)

The package resolves the shared library in this order:

1. `FIREPDF_LIB_PATH` (or Laravel `php-firepdf.lib_path`)
2. Bundled package path: `native/lib/-/`
3. Dev fallback: `native/pdf-inspector-ffi/target/release/`

If your production deployment does not set `FIREPDF_LIB_PATH`, make sure the package contains the prebuilt file under `native/lib/-/`.

### Build the Rust FFI bridge (local/dev)

[](#build-the-rust-ffi-bridge-localdev)

```
cd vendor/ferdiunal/php-firepdf/native/pdf-inspector-ffi
cargo build --release --locked

# copy the built file into package bundle layout
cd ../..
./scripts/stage-native-bundle.sh
```

### Build Bundles for Win/macOS/Linux

[](#build-bundles-for-winmacoslinux)

Use GitHub Actions workflow `native-bundles` to produce bundle artifacts for Linux, macOS, and Windows. The output folder name includes runner architecture (for example: `linux-x86_64`, `darwin-arm64`, `windows-x86_64`).

Each artifact contains:

- `native/lib/-/`

Include these files in the package release, or set `FIREPDF_LIB_PATH` explicitly at runtime.

### Laravel config (optional)

[](#laravel-config-optional)

```
php artisan vendor:publish --tag="php-firepdf-config"
```

Usage
-----

[](#usage)

### Standalone

[](#standalone)

```
use Ferdiunal\FirePdf\FirePdf;

$pdf = new FirePdf();

// Full processing: detect + extract + markdown
$result = $pdf->processPdf('document.pdf');
echo $result->pdfType;   // TextBased, Scanned, ImageBased, Mixed
echo $result->markdown;  // Markdown string or null

// Fast detection only
$info = $pdf->detectPdf('document.pdf');

// From bytes (no filesystem)
$bytes = file_get_contents('document.pdf');
$result = $pdf->processPdfBytes($bytes);

// Per-page markdown
$pages = $pdf->extractPagesMarkdown('document.pdf');
foreach ($pages->pages as $page) {
    echo "Page {$page->page}: {$page->markdown}";
}
```

### Laravel

[](#laravel)

```
use Ferdiunal\FirePdf\Facades\FirePdf;

$result = FirePdf::processPdf('document.pdf');
```

### Laravel AI SDK Tools (Laravel 13)

[](#laravel-ai-sdk-tools-laravel-13)

This package ships optional AI SDK-compatible tools under the `Ferdiunal\FirePdf\Ai\Tools` namespace:

- `DetectPdfTool`
- `ClassifyPdfTool`
- `ProcessPdfTool`
- `ExtractTextTool`
- `ExtractPagesMarkdownTool`

These tools follow the Laravel AI SDK `Tool` contract and can be returned explicitly from your agent's `tools()` method:

```
