Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pdf Pack Bundle Laravel Package

1tomany/pdf-pack-bundle

Symfony bundle wrapping the 1tomany/pdf-pack library for PDF extraction. Autowires read and convert actions to fetch metadata, rasterize pages to PNG, and extract text, with configurable Poppler binaries.

View on GitHub
Deep Wiki
Context7

PDF Extraction Bundle for Symfony

This package wraps the 1tomany/pdf-pack library into an easy to use Symfony bundle.

Installation

Install the bundle using Composer:

composer require 1tomany/pdf-pack-bundle

Configuration

Below is the complete configuration for this bundle. To customize it for your Symfony application, create a file named onetomany_pdfpack.yaml in config/packages/ and make the necessary changes.

onetomany_pdfpack:
    client: "poppler"
    poppler_client:
        pdfinfo_binary: "pdfinfo"
        pdftoppm_binary: "pdftppm"
        pdftotext_binary: "pdftotext"

Usage

Symfony will autowire the necessary classes after the bundle is installed. Any constructor argument typed with OneToMany\PdfPack\Contract\Action\ConvertActionInterface or OneToMany\PdfPack\Contract\Action\ReadActionInterface will allow you to interact with the concrete extractor client via the act() method.

<?php

namespace App\File\Action\Handler;

use OneToMany\PdfPack\Contract\Action\ConvertActionInterface;
use OneToMany\PdfPack\Contract\Action\ReadActionInterface;
use OneToMany\PdfPack\Transfer\Request\ConvertRequest;
use OneToMany\PdfPack\Transfer\Request\ReadRequest;

final readonly class UploadFileHandler
{
    public function __construct(
        private ReadActionInterface $readAction,
        private ConvertActionInterface $convertAction,
    ) {
    }

    public function handle(string $filePath): void
    {
        // Read PDF metadata like page count
        $request = new ReadRequest($filePath);

        // @see OneToMany\PdfPack\Transfer\Response\ReadResponse
        $response = $this->readAction->act($request);

        // Rasterize all pages of a PDF
        $request = new ConvertRequest($filePath)
            ->fromPage(1) // First page to extract
            ->toPage(null) // Last page to extract, NULL for all pages
            ->asPngOutput() // Generate PNG images
            ->atResolution(150); // At 150 DPI

        // @see OneToMany\PdfPack\Transfer\Response\ConvertResponse
        foreach ($this->convertAction->act($request) as $response) {
            // $response->getRecord()->getData()
        }

        // Extract text from pages 2 through 8
        $request = new ConvertRequest($filePath, 2, 8)->asTextOutput();

        // @see OneToMany\PdfPack\Transfer\Response\ConvertResponse
        foreach ($this->convertAction->act($request) as $response) {
            // $response->getRecord()->getData()
        }
    }
}

Testing

If you wish to avoid interacting with an external process in your test environment, you can take advantage of the MockClient by simply setting the onetomany_pdfpack.client parameter to the value "mock" in your Symfony service configuration for the test environment.

when@test:
    onetomany_pdfpack:
        client: "mock"

Without changing any other code, Symfony will automatically inject the MockClient instead of the default PopplerClient for your tests.

Creating your own client

Don't want to use Poppler? No problem! Create your own extractor class that implements the OneToMany\PdfPack\Contract\Client\ClientInterface interface and tag it accordingly.

<?php

namespace App\PdfPack\Client\Magick;

use OneToMany\PdfPack\Contract\Client\ClientInterface;
use OneToMany\PdfPack\Contract\Request\ConvertRequest;
use OneToMany\PdfPack\Contract\Request\ReadRequest;
use OneToMany\PdfPack\Contract\Response\ReadResponse;

final readonly class MagickClient implements ClientInterface
{
    /**
     * @see OneToMany\PdfPack\Contract\Client\ClientInterface
     */
    #[\Override]
    public function read(ReadRequest $request): ReadResponse
    {
        // Add your implementation here
    }

    /**
     * @see OneToMany\PdfPack\Contract\Client\ClientInterface
     */
    #[\Override]
    public function convert(ConvertRequest $request): \Generator
    {
        // Add your implementation here
    }
}
onetomany_pdfpack:
    client: "magick"

services:
    App\PdfPack\Client\Magick\MagickClient:
        tags:
            - { name: onetomany.pdfpack.client, key: magick }

That's it! Again, without changing any code, Symfony will automatically inject the correct extractor client for the action interfaces outlined above.

Credits

License

The MIT License

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator