All Projects → nucleos → NucleosDompdfBundle

nucleos / NucleosDompdfBundle

Licence: MIT license
📜 This bundle provides a wrapper for using dompdf inside symfony.

Programming Languages

PHP
23972 projects - #3 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to NucleosDompdfBundle

SonataDoctrineMongoDBAdminBundle
Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
Stars: ✭ 64 (+120.69%)
Mutual labels:  bundle, symfony-bundle
gulp-rev-versions-bundle
A bundle that allows symfony to get the version of assets versioned with gulp-rev
Stars: ✭ 13 (-55.17%)
Mutual labels:  bundle, symfony-bundle
Enqueue Bundle
[READ-ONLY] Message queue bundle for Symfony. RabbitMQ, Amazon SQS, Redis, Service bus, Async events, RPC over MQ and a lot more
Stars: ✭ 233 (+703.45%)
Mutual labels:  bundle, symfony-bundle
SlackBundle
SlackBundle for Symfony2 with Guzzle-Integration
Stars: ✭ 39 (+34.48%)
Mutual labels:  bundle, symfony-bundle
jsonrpc-bundle
JSON-RPC server for Symfony: exposes services registered in the service container as JSON-RPC-webservices
Stars: ✭ 31 (+6.9%)
Mutual labels:  bundle, symfony-bundle
Fmelfinderbundle
📁 ElFinderBundle provides ElFinder integration with TinyMCE, CKEditor, Summernote editors
Stars: ✭ 231 (+696.55%)
Mutual labels:  bundle, symfony-bundle
stampie-bundle
stampie.github.io/
Stars: ✭ 26 (-10.34%)
Mutual labels:  bundle, symfony-bundle
Gifexceptionbundle
😛 The GhostBuster of your exception page!
Stars: ✭ 197 (+579.31%)
Mutual labels:  bundle, symfony-bundle
SonataDashboardBundle
[Abandoned] Provides a Dashboard management through container and block services
Stars: ✭ 17 (-41.38%)
Mutual labels:  bundle, symfony-bundle
SensioBuzzBundle
No description or website provided.
Stars: ✭ 89 (+206.9%)
Mutual labels:  bundle, symfony-bundle
Victoire
Fullstack Symfony CMS: The perfect mix between a framework and a CMS
Stars: ✭ 227 (+682.76%)
Mutual labels:  bundle, symfony-bundle
connect-bundle
No description or website provided.
Stars: ✭ 35 (+20.69%)
Mutual labels:  bundle, symfony-bundle
Sonataintlbundle
Symfony SonataIntlBundle
Stars: ✭ 212 (+631.03%)
Mutual labels:  bundle, symfony-bundle
hashed-asset-bundle
Apply an asset version based on a hash of the asset for symfony/asset
Stars: ✭ 24 (-17.24%)
Mutual labels:  bundle, symfony-bundle
Liiphellobundle
[DEPRECATED] Alternative Hello World Bundle for Symfony2 using several FriendsOfSymfony Bundles
Stars: ✭ 206 (+610.34%)
Mutual labels:  bundle, symfony-bundle
Lexikmaintenancebundle
This Symfony2 bundle allows you to place your website in maintenance mode by calling two commands in your console. A page with status code 503 appears to users, it is possible to authorize certain ips addresses stored in your configuration.
Stars: ✭ 253 (+772.41%)
Mutual labels:  bundle, symfony-bundle
Sonatapagebundle
This bundle provides a Site and Page management through container and block services
Stars: ✭ 181 (+524.14%)
Mutual labels:  bundle, symfony-bundle
Mercure Bundle
The MercureBundle allows to easily push updates to web browsers and other HTTP clients in the Symfony full-stack framework, using the Mercure protocol.
Stars: ✭ 195 (+572.41%)
Mutual labels:  bundle, symfony-bundle
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (-17.24%)
Mutual labels:  bundle, symfony-bundle
LiipSearchBundle
[DEPRECATED] Google XML API for searching is discontinued
Stars: ✭ 35 (+20.69%)
Mutual labels:  bundle, symfony-bundle

NucleosDompdfBundle

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Continuous Integration Code Coverage Type Coverage

This bundle provides a wrapper for using dompdf inside Symfony.

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require nucleos/dompdf-bundle

Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in config/bundles.php file of your project:

// config/bundles.php

return [
    // ...
    Nucleos\DompdfBundle\NucleosDompdfBundle::class => ['all' => true],
];

Configure the Bundle

# config/packages/nucleos_dompdf.yaml

nucleos_dompdf:
    defaults:
        defaultFont: 'helvetica'
        # See https://github.com/dompdf/dompdf/wiki/Usage#options for available options

Usage

Whenever you need to turn a html page into a PDF use dependency injection for your service:

use Nucleos\DompdfBundle\Factory\DompdfFactoryInterface;
use Nucleos\DompdfBundle\Wrapper\DompdfWrapperInterface;

final class MyService
{
    public function __construct(DompdfFactoryInterface $factory)
    {
        $this->factory = $factory;
    }

    public function render()
    {
        // ...
        /** @var Dompdf\Dompdf $dompdf */
        $dompdf = $this->factory->create();
        // Or pass an array of options:
        $dompdf = $this->factory->create(['chroot' => '/home']);
        // ...
    }
}

final class MyOtherService
{
    public function __construct(DompdfWrapperInterface $wrapper)
    {
        $this->wrapper = $wrapper;
    }

    public function stream()
    {
        // ...
        $html = '<h1>Sample Title</h1><p>Lorem Ipsum</p>';

        /** @var Symfony\Component\HttpFoundation\StreamedResponse $response */
        $response = $this->wrapper->getStreamResponse($html, "document.pdf");
        $response->send();
        // ...
    }

    public function binaryContent()
    {
        // ...
        return $this->wrapper->getPdf($html);
        // ...
    }
}

Render pdf using Twig

If you use Twig to create the content, make sure to use renderView() instead of render(). Otherwise you might get the following HTTP header printed inside your PDF:

HTTP/1.0 200 OK Cache-Control: no-cache

$html = $this->renderView('my_pdf.html.twig', array(
    // ...
));
$this->wrapper->getStreamResponse($html, 'document.pdf');

Using asset() to link assets

First, make sure your chroot is correctly set and isRemoteEnabled is true.

# config/packages/nucleos_dompdf.yaml

nucleos_dompdf:
    defaults:
        chroot: '%kernel.project_dir%/public/assets'
        isRemoteEnabled: true

Second, use {{ absolute_url( asset() ) }}

<img src={{ absolute_url( asset('assets/example.jpg') ) }}>

Events

The dompdf wrapper dispatches events to conveniently get the inner dompdf instance when creating the PDF.

  • dompdf.output is dispatched in getPdf()
  • dompdf.stream is dispatched in streamHtml()

See Symfony Events and Event Listeners for more info.

License

This bundle is under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].