PHP code example of 1tomany / pdf-pack

1. Go to this page and download the library: Download 1tomany/pdf-pack library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

1tomany / pdf-pack example snippets




use OneToMany\PdfPack\Bridge\Poppler\PopplerProvider;
use OneToMany\PdfPack\Contract\Enum\OutputType;
use OneToMany\PdfPack\PdfClient;
use OneToMany\PdfPack\Resource\Registry;

$providers = new Registry([
    new PopplerProvider(),
]);

$pdfClient = new PdfClient('poppler', $providers);

$pdf = $pdfClient->files->read('/path/to/file.pdf');

foreach ($pdfClient->files->convert($pdf->path, outputType: OutputType::Png, resolution: 150) as $page) {
    // $page is created only when the generator advances
}

$pdf = $pdfClient->use('mock')->files->read('/path/to/file.pdf');



use OneToMany\PdfPack\Contract\PdfClientInterface;

final readonly class ExtractPdf
{
    public function __construct(
        private PdfClientInterface $pdfClient,
    ) {
    }
}



use OneToMany\PdfPack\Contract\Bridge\ProviderInterface;
use OneToMany\PdfPack\Contract\Enum\OutputType;
use OneToMany\PdfPack\Contract\Resource\FilesInterface;
use OneToMany\PdfPack\Resource\File\File;

final readonly class ImagickProvider implements ProviderInterface
{
    /**
     * @see OneToMany\PdfPack\Contract\Bridge\ProviderInterface
     *
     * @return 'imagick'
     */
    public static function getProvider(): string
    {
        return 'imagick';
    }

    // Implement the convert() and read() methods to satisfy the interface
}