PHP code example of daif / chrome-pdf-bundle

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

    

daif / chrome-pdf-bundle example snippets


// config/bundles.php

return [
    // ...
    Daif\ChromePdfBundle\DaifChromePdfBundle::class => ['all' => true],
];

namespace App\Controller;

use Daif\ChromePdfBundle\ChromePdfInterface;
use Symfony\Component\HttpFoundation\Response;

class InvoiceController
{
    public function generateInvoice(ChromePdfInterface $chromePdf): Response
    {
        return $chromePdf->html()
            ->content('invoice.html.twig', [
                'invoice' => $invoice,
            ])
            ->generate()
            ->stream()
        ;
    }
}

use Daif\ChromePdfBundle\ChromePdfInterface;

class ReportController
{
    public function generateReport(ChromePdfInterface $chromePdf): Response
    {
        return $chromePdf->url()
            ->url('https://example.com/report')
            ->generate()
            ->stream()
        ;
    }
}

use Daif\ChromePdfBundle\ChromePdfInterface;

class DocController
{
    public function generateDoc(ChromePdfInterface $chromePdf): Response
    {
        return $chromePdf->markdown()
            ->wrapper('wrapper.html.twig')
            ->files('content.md')
            ->generate()
            ->stream()
        ;
    }
}

use Daif\ChromePdfBundle\ChromeScreenshotInterface;

class ScreenshotController
{
    public function capture(ChromeScreenshotInterface $chromeScreenshot): Response
    {
        return $chromeScreenshot->html()
            ->content('page.html.twig')
            ->generate()
            ->stream()
        ;
    }
}