PHPackages                             aplusy/pdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. aplusy/pdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

aplusy/pdf
==========

Laravel 12 wrapper for PDF generation

v1.2.2(5mo ago)05MITPHPPHP ^8.2CI failing

Since Dec 6Pushed 5mo agoCompare

[ Source](https://github.com/aplusys/aplus-pdf)[ Packagist](https://packagist.org/packages/aplusy/pdf)[ RSS](/packages/aplusy-pdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (6)Used By (0)

Aplus PDF (Laravel Snappy Modernized)
=====================================

[](#aplus-pdf-laravel-snappy-modernized)

A modernized PDF generation package for Laravel, supporting multiple drivers including **wkhtmltopdf** and **Browsershot** (Headless Chrome). This package offers a fluent API, robust binary management, and easy testing utilities.

Features
--------

[](#features)

- **Multi-Driver Support**: Switch between `wkhtmltopdf` (legacy), `browsershot` (Puppeteer), and **Playwright** (Modern, Reliable) easily.
- **Fluent API**: Chainable methods for building PDFs (`Apdf::view('...')->save('...')`).
- **Binary Management**: Artisan commands to automatically install and verify dependencies (`wkhtmltopdf`, `puppeteer`, `chrome`).
- **Testing Fakes**: `Apdf::fake()` for asserting PDF generation without running binaries.
- **Queue Support**: Render PDFs in the background.

Installation
------------

[](#installation)

1. Install via Composer:

    ```
    composer require aplusy/pdf
    ```
2. Publish configuration (optional but recommended):

    ```
    php artisan vendor:publish --provider="Aplus\Pdf\PdfServiceProvider" --tag="config"
    ```

Binary Installation
-------------------

[](#binary-installation)

This package includes a powerful command to manage the underlying binaries required for PDF generation.

### Auto-Install (Recommended)

[](#auto-install-recommended)

To install the necessary binaries for your chosen driver:

```
# For wkhtmltopdf (Linux/Ubuntu)
php artisan pdf:install-binary wkhtmltopdf

# For Browsershot (Chrome/Puppeteer)
php artisan pdf:install-binary chromium

# For Playwright
php artisan pdf:install-binary playwright
```

#### Manual Playwright Installation

[](#manual-playwright-installation)

If the artisan command fails, you can install Playwright manually in your project root:

```
npm install playwright
npx playwright install
npx playwright install-deps
```

> **Note:** The `chromium` installation includes Puppeteer and a local Chrome binary. If you use `Browsershot`, you must have Node.js installed on your server.

### Manual Verification

[](#manual-verification)

Verify your installation:

```
php artisan pdf:verify /usr/local/bin/wkhtmltopdf
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Use the `Apdf` facade to generate PDFs from views, HTML, or URLs.

```
use Aplus\Pdf\Facades\Apdf;

// Download a PDF from a Blade view
return Apdf::view('invoices.show', ['invoice' => $invoice])
    ->download('invoice.pdf');

// Display inline in browser
return Apdf::html('Hello World')
    ->inline('hello.pdf');

// Save to disk
Apdf::url('https://google.com')
    ->save(storage_path('app/google.pdf'));
```

### Driver Selection

[](#driver-selection)

You can switch drivers at runtime:

```
Apdf::driver('browsershot')
    ->view('reports.complex-chart')
    ->save('report.pdf');

// Or change driver in the chain:
Apdf::view('invoice')
    ->driver('browsershot')
    ->save('invoice.pdf');
```

Or configure the default driver in `config/aplus-pdf.php`.

### Options

[](#options)

Pass driver-specific options easily:

```
Apdf::view('document')
    ->setOption('margin-top', '20mm') // wkhtmltopdf option
    ->setOption('landscape', true)    // Browsershot option
    ->save('doc.pdf');
```

### Asynchronous Rendering

[](#asynchronous-rendering)

Dispatch a job to render the PDF in the background:

```
use Aplus\Pdf\Jobs\RenderPdfJob;

RenderPdfJob::dispatch(
    'emails.order-confirmation',
    ['order' => $order],
    's3',
    'invoices/order-123.pdf'
);
```

### Zero Margins

[](#zero-margins)

To achieve true zero margins, you must ensure two things:

1. Set the PDF driver margins to `0` (or `'0mm'`).
2. Remove the default browser margin from your HTML/Blade view using CSS.

```

    body {
        margin: 0;
        padding: 0;
    }

```

If you still see white space, ensure `disable-smart-shrinking` is enabled in `config/aplus-pdf.php`.

Testing
-------

[](#testing)

Use `Apdf::fake()` to verify PDF generation logic without actually rendering files.

```
use Aplus\Pdf\Facades\Apdf;

public function test_invoice_download()
{
    Apdf::fake();

    $response = $this->get('/invoice/1');

    Apdf::assertRenderedHtml('Invoice #1');

    // If you used view()
    // Apdf::assertRenderedHtml('...'); // PdfFake captures the rendered HTML
}
```

Configuration
-------------

[](#configuration)

The `config/aplus-pdf.php` file allows you to configure defaults for each driver.

```
return [
    'default' => 'wkhtmltopdf',

    'drivers' => [
        'wkhtmltopdf' => [
            'binary' => env('WKHTMLTOPDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
            'options' => [],
            'timeout' => 3600,
        ],

        'browsershot' => [
            'node_binary' => env('NODE_BINARY', '/usr/bin/node'),
            'npm_binary' => env('NPM_BINARY', '/usr/bin/npm'),
            'modules_path' => base_path('node_modules'),
        ],

        'playwright' => [
            'node_binary' => env('NODE_BINARY', '/usr/bin/node'),
            'npm_binary' => env('NPM_BINARY', '/usr/bin/npm'),
            'timeout' => 60,
        ],
    ],
    // ...
];
```

Troubleshooting
---------------

[](#troubleshooting)

- **"Cannot find module 'puppeteer'"**: Run `php artisan pdf:install-binary chromium` or `npm install puppeteer` in your project root.
- **"wkhtmltopdf: cannot connect to X server"**: Ensure you are using the headless version (usually default in recent versions) or install `xvfb-run` wrapper.

Playwright Configuration service
--------------------------------

[](#playwright-configuration-service)

This package automatically handles the Playwright browser cache location using `storage/playwright`. You generally **do not** need a custom `.playwrightrc` or config file for this aspect, as the package enforces the path via environment variables during installation and execution.

However, if you wish to customize other behavior globally for Playwright in your project, you can use standard Playwright config files, but note that `Aplus\Pdf` manages the `launch` options specifically for PDF tasks.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance71

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

162d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/02d26d60360bd215660be5e46ce2ed6ffd2622f86fff20ed69cd729c1463c2e5?d=identicon)[aplus-yemen](/maintainers/aplus-yemen)

---

Top Contributors

[![ALSABRI87](https://avatars.githubusercontent.com/u/63615782?v=4)](https://github.com/ALSABRI87 "ALSABRI87 (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aplusy-pdf/health.svg)

```
[![Health](https://phpackages.com/badges/aplusy-pdf/health.svg)](https://phpackages.com/packages/aplusy-pdf)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

7.3k87.6M278](/packages/barryvdh-laravel-dompdf)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3542.7M5](/packages/elibyy-tcpdf-laravel)[stevebauman/autodoc-facades

Auto-generate PHP doc annotations for Laravel facades

98186.6k9](/packages/stevebauman-autodoc-facades)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
