PHP code example of phpsoftbox / pdf

1. Go to this page and download the library: Download phpsoftbox/pdf 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/ */

    

phpsoftbox / pdf example snippets


use PhpSoftBox\Pdf\Gotenberg\GotenbergHtmlPdfRenderer;
use PhpSoftBox\Pdf\PdfMargins;
use PhpSoftBox\Pdf\PdfPageSize;
use PhpSoftBox\Pdf\PdfRenderOptions;
use PhpSoftBox\Pdf\PdfUnit;

$renderer = new GotenbergHtmlPdfRenderer(
    client: $client,
    requestFactory: $requestFactory,
    streamFactory: $streamFactory,
    baseUrl: 'http://gotenberg:3000',
);

$document = $renderer->renderHtml(
    html: '<html><body>Этикетка #1</body></html>',
    options: new PdfRenderOptions(
        pageSize: new PdfPageSize(58, 40, PdfUnit::Mm),
        margins: PdfMargins::all(1, PdfUnit::Mm),
        printBackground: true,
    ),
);

$options = PdfRenderOptions::labelMm(58, 40, marginMm: 1);

use PhpSoftBox\Pdf\Http\PdfHttpResponder;

$responder = new PdfHttpResponder($responseFactory, $streamFactory);

// Просмотр в браузере
$response = $responder->inline($document, 'label.pdf');

// Скачивание файла
$response = $responder->download($document, 'label.pdf');

use PhpSoftBox\Pdf\Batch\PdfChunkPlanner;

$chunks = PdfChunkPlanner::split(totalPages: 1200, pagesPerChunk: 250);
// 1-250, 251-500, 501-750, 751-1000, 1001-1200