Download the PHP package vaneetjoshi/laravel-pdf without Composer
On this page you can find all versions of the php package vaneetjoshi/laravel-pdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaneetjoshi/laravel-pdf
More information about vaneetjoshi/laravel-pdf
Files in vaneetjoshi/laravel-pdf
Package laravel-pdf
Short Description A pure-PHP, shared-hosting friendly PDF engine for Laravel with advanced Devanagari and Sanskrit OTL script support.
License MIT
Informations about the package laravel-pdf
Laravel PDF Builder
A fluent, pure-PHP PDF builder for Laravel.
Generating PDFs in PHP is traditionally a frustrating experience involving clunky syntax, massive configuration arrays, and layout limitations. This library changes that. It wraps the powerful mPDF engine in a beautiful, chainable Laravel API, making PDF creation an absolute breeze.
Beyond an incredible Developer Experience (DX), this package introduces a custom Two-Pass Letterhead Engine to solve the most complex layout limitations in modern PDF generation. It seamlessly renders full-page repeating borders, background canvases, and persistent headers/footers without triggering bounding-box collisions or margin collapse. Furthermore, it boasts built-in OTL (OpenType Layout) support to render complex Hindi/Sanskrit ligatures flawlessly.
Because it relies purely on PHP, this package is 100% shared-hosting friendly. No Node.js, Puppeteer, or headless browsers are required.
🌟 Why Choose This Library?
- Incredibly Easy API: Say goodbye to raw mPDF arrays. Use elegant, chainable methods like
Pdf::paperSize('A4')->margins(10, 10, 10, 10)->loadView('invoice')->stream(). - Two-Pass Rendering Engine: Flawless full-page borders and backgrounds alongside headers/footers without crashing the layout matrix.
- Native Sanskrit / Devanagari (OTL): Built-in OpenType Layout engine support to render complex Indian ligatures perfectly out of the box.
- Direct Memory Workflows: Generate PDFs and attach them directly to emails or return them as Base64 JSON strings without ever touching the disk.
📋 Server Requirements
- PHP:
^8.2,^8.3,^8.4 - Laravel:
^11.0,^12.0,^13.0 - Extensions:
gdorimagick(for image processing),mbstring.
🚀 Installation
Install via Composer:
Publish the configuration file:
⚠️ CSS Limitations & Gotchas
Because this package wraps mPDF under the hood, it uses an older, specific HTML/CSS parsing engine. To avoid rendering headaches, please follow these rules:
- No Flexbox or CSS Grid: Do not use
display: flex;ordisplay: grid;. They will be ignored. - Use Tables for Layouts: For columns and grids (like invoices), rely on classic HTML
<table width="100%">layouts. - Header/Footer Fonts: mPDF detaches headers and footers from the main DOM. CSS classes defined in your
<style>tags usually will not apply to headers. If you need a custom font in a header, use inline styles:<div style="font-family: devanagari, sans-serif;">.
🖋 Adding Custom Fonts
You can easily register your own fonts (like Poppins, Roboto, etc.) by placing the .ttf files in your designated font folder and mapping them in the published config/pdf.php file:
You can now use font-family: poppins, sans-serif; in your Blade views.
💻 Real-World Implementation Examples
1. Generating a Tax Invoice (Controller & Blade)
Here is a complete example of generating a professional, bordered invoice.
The Controller:
The Blade View (resources/views/pdf/invoice.blade.php):
2. Emailing a PDF Directly (Without Saving to Disk)
If you want to generate an invoice and email it to a customer immediately without cluttering your server's storage, use the output() method to get the raw binary data and attach it via Laravel's Mail facade.
3. Creating Complex Borders & Sanskrit Rendering
Perfect for Astrology Reports, Certificates, or intricate documents.
🛠 API Reference
Initialization & Configuration
paperSize(string $size)- Set standard paper sizes (A4, Letter, Legal).orientation(string $orientation)- 'P' (Portrait) or 'L' (Landscape).margins(float $top, float $right, float $bottom, float $left)- Set document body margins.displayMode(string $mode)- Set PDF viewer mode ('fullpage', 'fullwidth', etc).withSanskrit()- Enables Devanagari rendering engine.
Layout & Injection
loadView(string $view, array $data)- Load a Laravel Blade view.loadHtml(string $html)- Parse a raw HTML string.addStylesheet(string $path)- Inject an external CSS file.headerHtml(string $html, ?float $offsetY)- Inject HTML into the header. (Use inlinefont-familyfor custom header fonts).footerHtml(string $html, ?float $offsetY)- Inject HTML into the footer.showPageNumbers(string $position, string $format)- Quick pagination helper (e.g., 'bottom-right', 'Page {PAGENO} of {nbpg}').
Borders, Backgrounds & Security
addEdgeBorder(array $options)- Create absolute full-page repeating borders.pageBackground(?string $color, ?string $imageUrl, string $resizeMode, string $position)- Set page canvas background.watermarkText(string $text, float $alpha, string $font)- Add a diagonal text watermark.watermarkImage(string $path, float $alpha)- Add a background image watermark.protect(string $password, array $permissions)- Restrict printing/copying and encrypt the PDF.
Output Methods
stream(?string $filename)- Display the PDF in the browser.download(?string $filename)- Force a file download.saveToDisk(string $disk, string $path)- Save directly to Laravel Storage (e.g., 's3', 'public').base64()- Output as a base64 string.output()- Output as a raw binary string.
📚 PdfBuilder Complete API Reference
All methods belong to the Vaneetjoshi\LaravelPdf\PdfBuilder class and can be chained via the Pdf Facade or pdf() helper function.
1. Instantiation & Core Configuration
__construct()
- Description: Initializes a new instance of
PdfBuilderand automatically loads defaults fromconfig/pdf.php. - Parameters: None
- Returns:
PdfBuilder - Example:
paperSize()
- Description: Sets the physical paper dimensions of the document.
- Signature:
paperSize(string $size = 'A4'): self -
Parameters: Parameter Type Default Accepted / Valid Values Description $sizestring'A4''A0'–'A10','B0'–'B10','Letter','Legal','Executive','Tabloid'Standard paper size dimension. - Returns:
self(Chainable) - Example:
orientation()
- Description: Configures the page orientation (Portrait or Landscape).
- Signature:
orientation(string $orientation = 'P'): self -
Parameters: Parameter Type Default Accepted / Valid Values Description $orientationstring'P''P','Portrait','L','Landscape'Document orientation mode. - Returns:
self(Chainable) - Example:
margins()
- Description: Sets the inner content margins (padding) for the main body in millimeters.
- Signature:
margins(float $top = 15, float $right = 15, float $bottom = 15, float $left = 15): self -
Parameters: Parameter Type Default Accepted Values Description $topfloat15Any positive float (mm) Distance between top page edge and body content. $rightfloat15Any positive float (mm) Distance between right page edge and body content. $bottomfloat15Any positive float (mm) Distance between bottom page edge and body content. $leftfloat15Any positive float (mm) Distance between left page edge and body content. - Returns:
self(Chainable) - Note: When using
addEdgeBorder(), body margins automatically auto-expand if the configured border size plus padding exceeds these values. - Example:
displayMode()
- Description: Dictates how PDF viewing software (e.g., Adobe Acrobat, Chrome PDF Viewer) displays the file upon opening.
- Signature:
displayMode(string $mode): self -
Parameters: Parameter Type Default Accepted / Valid Values Description $modestringN/A 'fullpage','fullwidth','real','default','none'PDF display scaling mode. - Returns:
self(Chainable) - Example:
2. Content & Styling Loaders
loadView()
- Description: Compiles a Blade template view with data and loads the generated HTML as the document body.
- Signature:
loadView(string $view, array $data = []): self -
Parameters: Parameter Type Default Accepted Values Description $viewstringN/A Valid Blade view path (e.g. 'pdf.invoice')Dot-notation blade path. $dataarray[]Key-value associative array Variables passed into the Blade view. - Returns:
self(Chainable) - Example:
loadHtml()
- Description: Parses a raw HTML markup string directly into the document body.
- Signature:
loadHtml(string $html): self -
Parameters: Parameter Type Default Accepted Values Description $htmlstringN/A Valid HTML string Raw string containing HTML markup. - Returns:
self(Chainable) - Example:
addStylesheet()
- Description: Reads a local CSS file from disk and injects its contents into the document
<head>CSS context. - Signature:
addStylesheet(string $path): self -
Parameters: Parameter Type Default Accepted Values Description $pathstringN/A Absolute server path to .cssfileFile path (e.g., public_path('css/pdf.css')). - Returns:
self(Chainable) - Example:
withSanskrit()
- Description: Activates the OpenType Layout (OTL) engine for Devanagari script processing and injects CSS classes for rendering Sanskrit ligatures correctly.
- Signature:
withSanskrit(): self - Parameters: None
- Returns:
self(Chainable) - Example:
3. Headers, Footers & Pagination
headerHtml()
- Description: Binds custom HTML to the persistent top page header region (
<htmlpageheader>). - Signature:
headerHtml(string $html, ?float $offsetY = null, ?float $offsetX = null): self -
Parameters: Parameter Type Default Accepted Values Description $htmlstringN/A Valid HTML string Header markup. Use inline font-familystyles for non-default fonts.$offsetYfloat|nullnullPositive float (mm) Distance of header from top edge. $offsetXfloat|nullnullPositive float (mm) Left & right padding offset in mm. - Returns:
self(Chainable) - Example:
footerHtml()
- Description: Binds custom HTML to the persistent bottom page footer region (
<htmlpagefooter>). - Signature:
footerHtml(string $html, ?float $offsetY = null, ?float $offsetX = null): self -
Parameters: Parameter Type Default Accepted Values Description $htmlstringN/A Valid HTML string Footer markup. $offsetYfloat|nullnullPositive float (mm) Distance of footer from bottom edge. $offsetXfloat|nullnullPositive float (mm) Left & right padding offset in mm. - Returns:
self(Chainable) - Example:
showPageNumbers()
- Description: Automatically injects formatted pagination text into the header or footer.
- Signature:
showPageNumbers(string $position = 'bottom-right', string $format = 'Page {PAGENO} of {nbpg}'): self -
Parameters: Parameter Type Default Accepted Values Description $positionstring'bottom-right''bottom-right','bottom-left','bottom-center','top-right','top-left','top-center'Screen placement for the pagination string. $formatstring'Page {PAGENO} of {nbpg}'String containing {PAGENO}and{nbpg}Formatting string. {PAGENO}= Current Page,{nbpg}= Total Pages. - Returns:
self(Chainable) - Example:
4. Two-Pass Backgrounds & Borders Engine
addEdgeBorder()
- Description: Triggers the Pass 1 Canvas Engine to draw repeating or solid full-bleed borders around every page edge without colliding with main body margins.
- Signature:
addEdgeBorder(array $options = []): self -
Parameters: Parameter Type Default Accepted Options / Structure Description $optionsarray[]See structure array below Multi-edge layout configuration array. -
Options Array Structure:
- Returns:
self(Chainable) - Example:
pageBackground()
- Description: Paints a uniform background color or repeating texture image across the Pass 1 background canvas.
- Signature:
pageBackground(?string $color = null, ?string $imageUrl = null, string $resizeMode = '4', string $position = 'center center'): self -
Parameters: Parameter Type Default Accepted Values Description $colorstring|nullnullHex color string (e.g., '#fffbf0')Background fill color. $imageUrlstring|nullnullURL or server path to image file Background pattern or texture URL. $resizeModestring'4''0'(no resize),'1'(fit),'2'(fill),'4'(scale page)Scaling factor for background image. $positionstring'center center'Standard CSS background-positionBackground image alignment. - Returns:
self(Chainable) - Example:
5. Security & Watermarking
watermarkText()
- Description: Renders a diagonal semi-transparent text watermark across the center of every page.
- Signature:
watermarkText(string $text, float $alpha = 0.2, string $font = 'dejavusans'): self -
Parameters: Parameter Type Default Accepted Values Description $textstringN/A Any text string Watermark text string (e.g. 'CONFIDENTIAL').$alphafloat0.20.0(invisible) to1.0(opaque)Transparency level. $fontstring'dejavusans'Valid font family registered in config Font family for watermark. - Returns:
self(Chainable) - Example:
watermarkImage()
- Description: Renders a semi-transparent image watermark across every page.
- Signature:
watermarkImage(string $path, float $alpha = 0.2, string|array $size = 'D', string|array $position = 'P'): self -
Parameters: Parameter Type Default Accepted Values Description $pathstringN/A URL or absolute local file path Path to logo or mark. $alphafloat0.20.0to1.0Transparency level. $sizestring|array'D''D'(default),'P'(proportional),'F'(fit), or[w, h]Sizing algorithm. $positionstring|array'P''P'(center) or[x, y]coordinate arrayScreen positioning. - Returns:
self(Chainable) - Example:
protect()
- Description: Encrypts the PDF file with 128-bit encryption and limits user permissions.
- Signature:
protect(string $password, array $permissions = ['print', 'copy']): self -
Parameters: Parameter Type Default Accepted Values Description $passwordstringN/A Any non-empty string Encryption password. $permissionsarray['print', 'copy']Array containing: 'print','modify','copy','annot-forms','fill-forms','extract','assemble','print-highres'Allowed user permissions. - Returns:
self(Chainable) - Example:
6. Output Generators
stream()
- Description: Compiles the document and sends HTTP headers to stream the PDF directly inline in the browser.
- Signature:
stream(?string $filename = null): mixed -
Parameters: Parameter Type Default Accepted Values Description $filenamestring|nullnullFilename ending in .pdfName shown in browser tab. Defaults to 'document.pdf'. - Returns:
\Symfony\Component\HttpFoundation\Response - Example:
download()
- Description: Compiles the document and forces the user's browser to download the file.
- Signature:
download(?string $filename = null): mixed -
Parameters: Parameter Type Default Accepted Values Description $filenamestring|nullnullFilename ending in .pdfDownload file name. Defaults to 'document.pdf'. - Returns:
\Symfony\Component\HttpFoundation\Response - Example:
saveToDisk()
- Description: Compiles the document and saves the raw binary file directly to a configured Laravel filesystem disk.
- Signature:
saveToDisk(string $disk = 'public', string $path = 'documents/doc.pdf'): bool -
Parameters: Parameter Type Default Accepted Values Description $diskstring'public'Valid disk name defined in config/filesystems.php(e.g.'s3','local')Target Laravel Storage disk. $pathstring'documents/doc.pdf'Destination file path Target folder and file name. - Returns:
bool(trueon successful write,falseon failure) - Example:
base64()
- Description: Compiles the document in memory and returns a Base64-encoded string representation. Ideal for API payloads.
- Signature:
base64(): string - Parameters: None
- Returns:
string(Base64 string) - Example:
output()
- Description: Compiles the document in memory and returns the raw binary PDF stream. Ideal for emailing attachments directly via
Mail::attachData(). - Signature:
output(): string - Parameters: None
- Returns:
string(Raw PDF binary stream) - Example:
All versions of laravel-pdf with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/view Version ^11.0|^12.0|^13.0
illuminate/filesystem Version ^11.0|^12.0|^13.0
mpdf/mpdf Version ^8.2