Laravel EnsoLaravel Enso
Guide
Back End
Front End
GitHub
Guide
Back End
Front End
GitHub
  • Back End

    • Action Logger
    • Addresses
    • Algolia
    • Algolia Webshop
    • API
    • Audits
    • Avatars
    • Cache Chain
    • Calendar
    • Cargo Partner
    • Categories
    • Charts
    • CI/CD
    • Cli
    • CNP Validator
    • Comments
    • Commercial
    • Companies
    • Core
    • Countries
    • Currencies
    • Data Export
    • Data Import
    • Discounts
    • Documents
    • Dynamic Methods
    • EAV
    • Emag
    • Enums
    • Excel
    • Facebook
    • Files
    • Filters
    • Financials
    • Forms
    • Frisbo
    • Google
    • Helpers
    • Holidays
    • How-to
    • Image Transformer
    • Impersonate
    • Interactions
    • Inventory
    • IO
    • Localisation
    • Lockable Models
    • Logs
    • Measurement Units
    • Meili Search
    • Meili Search Webshop
    • Menus
    • Migrator
    • Monitored Emails
    • Notifications
    • Packaging Units
    • PDF
    • People
    • Permissions
    • Product Eav
    • Product Lots
    • Products
    • Questionnaires
    • Rememberable
    • Roles
    • Sale Channels
    • Searchable
    • Select
    • Sentry
    • Services
    • Smart Bill
    • Sms Advert
    • Stripe
    • Tables
    • Tasks
    • Teams
    • Ticketing
    • Track Who
    • Tutorials
    • Typesense
    • Typesense Webshop
    • Unit Conversion
    • Upgrade
    • UPS
    • User Groups
    • Users
    • Versions
    • Virtual Call Center
    • Vouchers
    • Webshop
    • Webshop Commercial

PDF

LicenseStableDownloadsPHPIssuesMerge Requests

Description

Pdf provides a small Laravel Enso wrapper around Snappy / wkhtmltopdf for generating PDF documents from Blade views.

The package exposes a fluent Pdf service that applies Enso's default page settings, loads a view with data, and then lets the caller inline, download, save, or output the rendered PDF.

It is used across the ecosystem for invoices, orders, delivery notes, stock documents, and other printable documents that need a consistent PDF pipeline.

Installation

Install the package:

composer require laravel-enso/pdf

The package relies on barryvdh/laravel-snappy, which in turn requires a working wkhtmltopdf binary in the target environment.

No additional provider registration is needed beyond Composer's package discovery.

Features

  • Wraps barryvdh/laravel-snappy in a small fluent service.
  • Loads Blade views with arbitrary data before rendering.
  • Streams PDFs inline in the browser.
  • Supports file download responses.
  • Supports saving generated PDFs to disk.
  • Exposes raw PDF output as a string.
  • Ships with Enso defaults for paper size, margins, orientation, and footer pagination.

Usage

Generate a PDF from a Blade view:

use LaravelEnso\Pdf\Services\Pdf;

return (new Pdf())
    ->loadView('documents.order', ['order' => $order])
    ->inline('order.pdf');

Download instead of inlining:

return (new Pdf())
    ->loadView('documents.invoice', ['invoice' => $invoice])
    ->download('invoice.pdf');

Save the generated file:

(new Pdf())
    ->loadView('documents.note', ['model' => $model])
    ->save(storage_path('app/temp/document.pdf'));

Switch to landscape and override options when needed:

$pdf = (new Pdf())
    ->landscape()
    ->setOption('margin-top', 5)
    ->loadView('documents.report', ['report' => $report]);

Note

This package is only a wrapper around Snappy. Rendering still depends on the availability and correctness of the underlying wkhtmltopdf binary in the running environment.

API

Contracts

  • LaravelEnso\Pdf\Contracts\GeneratesPdf
  • LaravelEnso\Pdf\Contracts\SavesPdf

GeneratesPdf defines:

  • inline(): Response
  • output(): string

SavesPdf defines:

  • save()

Pdf Service

LaravelEnso\Pdf\Services\Pdf

Public methods:

  • __construct()
  • inline(string $filename = 'document.pdf'): Response
  • output(): string
  • save($filename, $overwrite = false): PdfWrapper
  • download(string $filename): Response
  • landscape(): self
  • setOption(string $option, $value): self
  • loadView(string $view, array $attributes): self

Default options applied in the factory:

  • paper: a4
  • orientation: portrait
  • margin-top: 10
  • margin-left: 5
  • margin-right: 5
  • margin-bottom: 10
  • footer-font-size: 8
  • footer-center: "Page [page] from [toPage]"

Depends On

Framework dependency:

  • laravel/framework ↗

External dependencies:

  • barryvdh/laravel-snappy ↗
  • wkhtmltopdf ↗

Contributions

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

Edit this page on GitHub
Last Updated: 4/19/2026, 7:25:53 PM
Prev
Packaging Units
Next
People