PHP code example of rekalogika / gotenberg-pdf-bundle

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

    

rekalogika / gotenberg-pdf-bundle example snippets

 title="src/Controller/AppController.php"
namespace App\Controller;

use Rekalogika\Contracts\Print\PageOrientation;
use Rekalogika\Contracts\Print\PdfGeneratorInterface;
use Rekalogika\Print\PageLayout;
use Rekalogika\Print\Paper;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Annotation\Route;

class AppController extends AbstractController
{
    #[Route('/pdf')]
    public function index(PdfGeneratorInterface $pdfGenerator): Response
    {
        $pdf = $pdfGenerator->generatePdfFromHtml(
            htmlContent: '<h1>Hello World</h1>',
            paper: Paper::A4(),
            pageLayout: PageLayout::inMm(PageOrientation::Portrait, 30)
        );

        return new StreamedResponse(
            callback: fn () => fpassthru($pdf->detach()),
            status: 200,
            headers: [
                'Content-Type' => 'application/pdf',
            ]
        );
    }
}