- How do I install smalot/pdfparser in a Laravel application?
- Install it with Composer by running composer require smalot/pdfparser in your Laravel project root. The package is a standalone PHP library with no external dependencies beyond PHP, so Laravel's Composer-based dependency system handles it without framework-specific changes. Composer will update your composer.json and lock file, and the parser classes are autoloaded like any other package.
- Is smalot/pdfparser compatible with Laravel 10 and Laravel 11?
- Yes, it works through Composer and does not require Laravel-specific integration. The library requires PHP 7.1+ since v1, and recent fixes target PHP 8.1+ behavior, which aligns with the PHP versions Laravel 10 and 11 typically run. Still, pin a stable release and test against your app's PHP version and PDF corpus before upgrading.
- How do I extract text from a PDF in Laravel with smalot/pdfparser?
- Create a Smalot\PdfParser\Parser instance, call parseFile on the PDF path, then call getText on the returned document object. In Laravel you can wrap this in a service class, job, or controller and store the extracted text in your database or pass it to Laravel Scout. The README quick example uses parser->parseFile('/path/to/document.pdf') and $pdf->getText().
- Can smalot/pdfparser extract metadata such as author and title from a PDF?
- Yes, the library can extract metadata including author and description, and it also exposes parsed objects and headers. Use the document object returned by the parser and call its metadata methods; see the package usage documentation for exact method names. Metadata extraction is one of the core PDF-specific features alongside text extraction.
- Should I use smalot/pdfparser v2.13.0-beta1 in production?
- No. The maintainer explicitly marks v2.13.0-beta1 as beta and warns it may contain changes that could affect production systems. Pin production to v2.12.5 and treat the beta as a staging or evaluation target only. The 2.13 line rewrites core internals such as incremental object construction and chunked section parsing, so extraction output on borderline documents may differ.
- Is smalot/pdfparser actively maintained?
- The project is under limited maintenance. It is kept compatible with supported PHP versions and community fixes may be accepted, but there is no active feature development and no guarantee that pull requests will be reviewed or merged quickly. Recent first-time contributor fixes are a modest positive signal, but treat the library as feature-stable and security-patch-oriented rather than roadmap-driven.
- Does smalot/pdfparser support encrypted or password-protected PDFs?
- No, secured documents are not supported unless you manually decrypt or pre-process them before parsing. The README lists secured documents as unsupported, along with form data extraction. If your Laravel upload flow accepts password-protected PDFs, plan a separate decryption or rejection path.
- Can smalot/pdfparser extract filled-in PDF form data?
- No, form data extraction is explicitly listed as unsupported. The library focuses on text, metadata, headers, and parsed objects rather than AcroForm field values. For form-heavy workflows you will need a different tool or custom handling.
- What are the memory and denial-of-service risks of parsing untrusted PDFs with smalot/pdfparser?
- The 2.13 line materially improves memory and DoS posture with chunked section parsing, incremental object building, and removal of a quadratic-time placeholder replacement path. Those changes reduce peak memory and make adversarial input scaling linear on that path, but they do not eliminate risk. For untrusted uploads in Laravel, combine the parser with file size limits, queue workers, timeouts, and isolated processing.
- How should I test a smalot/pdfparser upgrade in a Laravel app?
- Diff-test the new version against a golden corpus of real production PDFs and compare extracted text and metadata with the currently pinned release. Include malformed or nested PDFs that exercise the Font::getDetails() indirect Encoding TypeError fixed in PR #823 and PHP 8.1+ float-to-int cast case fixed in PR #841. Because the beta rewrites parser internals, do not rely on unit tests alone; validation needs representative documents.