Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Chrome Pdf Bundle Laravel Package

daif/chrome-pdf-bundle

View on GitHub
Deep Wiki
Context7

MarkdownPdfBuilder

Convert Markdown files into PDF. The Markdown is first converted to HTML using league/commonmark, then rendered to PDF via Chrome.

Basic usage

Twig wrapper

Wrap your Markdown content in a Twig template:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My PDF</title>
    </head>
    <body>
        {{ markdown_content }}
    </body>
</html>
namespace App\Controller;

use Daif\ChromePdfBundle\ChromePdfInterface;

class YourController
{
    public function yourControllerMethod(ChromePdfInterface $chromePdf): Response
    {
        return $chromePdf->markdown()
            ->wrapper('wrapper.html.twig', [
                'my_var' => 'value'
            ])
            ->files('content.md')
            ->generate()
            ->stream()
         ;
    }
}

HTML wrapper

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My PDF</title>
    </head>
    <body>
        <!-- Markdown content will be inserted here -->
    </body>
</html>
namespace App\Controller;

use Daif\ChromePdfBundle\ChromePdfInterface;

class YourController
{
    public function yourControllerMethod(ChromePdfInterface $chromePdf): Response
    {
        return $chromePdf->markdown()
            ->wrapperFile('../templates/wrapper.html')
            ->files('content.md')
            ->generate()
            ->stream()
         ;
    }
}

Available methods

All methods from HtmlPdfBuilder are available, plus:

Method Description
files(Stringable|string ...$paths) Markdown files to convert
wrapper(string $template, array $context) Twig wrapper template
wrapperFile(string $path) HTML wrapper file

Examples

Multiple Markdown files with styling

$chromePdf->markdown()
    ->wrapper('styled_wrapper.html.twig', [
        'title' => 'Documentation',
    ])
    ->files('chapter1.md', 'chapter2.md', 'chapter3.md')
    ->paperStandardSize(PaperSize::A4)
    ->printBackground()
    ->generate()
    ->stream()
;
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui