Weave 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.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log