PHPackages                             backpack/download-operation - 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. backpack/download-operation

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

backpack/download-operation
===========================

Quickly add a Download button to your Laravel/Eloquent entries. But let's face it, you'll use this as Download Invoice PDF, won't you?

2.4.1(4mo ago)133.5k↓16.7%5MITPHPCI failing

Since Dec 4Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/Laravel-Backpack/download-operation)[ Packagist](https://packagist.org/packages/backpack/download-operation)[ Docs](https://github.com/laravel-backpack/download-operation)[ RSS](/packages/backpack-download-operation/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (13)Used By (0)

DownloadOperation
=================

[](#downloadoperation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4554444a0cbe1f52ed2718cef547a7b4dfb61b85c3fdf3ee7addc7ce13bcade0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261636b7061636b2f646f776e6c6f61642d6f7065726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/backpack/download-operation)[![Total Downloads](https://camo.githubusercontent.com/5b4823bdfcf1c55375d5e7fd8543a380116263570a2657c47b5ae302819cbff9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6261636b7061636b2f646f776e6c6f61642d6f7065726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/backpack/download-operation)[![The Whole Fruit Manifesto](https://camo.githubusercontent.com/9fc65ecdd629dc33c369f73e0bc051740f01647367c131a574577fea2a5678bb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f77726974696e672532307374616e646172642d74686525323077686f6c6525323066727569742d627269676874677265656e)](https://github.com/the-whole-fruit/manifesto)

This package provides a way to add "Download" buttons to your Backpack CRUDs. By default:

- the file format will be a PDF;
- the file will show a list of CRUD fields, similar to the [Show Operation](https://backpackforlaravel.com/docs/5.x/crud-operation-show);

Demo
----

[](#demo)

[![Backpack Download and BulkDownload buttons](https://user-images.githubusercontent.com/1032474/101194862-3f82cc00-3667-11eb-856c-25c21f0181a5.gif)](https://user-images.githubusercontent.com/1032474/101194862-3f82cc00-3667-11eb-856c-25c21f0181a5.gif)

Requirements
------------

[](#requirements)

This package uses [Backpack for Laravel](https://backpackforlaravel.com/) (of course) but also [spatie/browsershot](https://github.com/spatie/browsershot/), which itself uses Puppeteer, which itself uses a headless Chrome browser to generate the PDFs. Because of that:

- PRO: you don't need to code special views for them to look good in PDF form; if it looks good in the browser, it'll probably look good in the PDF;
- CON: you need to install a bunch of stuff on your server (Puppeteer and Chrome); so you probably can't use this on shared hosting;

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

[](#installation)

**Step 0.** Install [Puppeteer](https://spatie.be/docs/browsershot/v4/requirements) and [spatie/browsershot](https://github.com/spatie/browsershot/), as instructed by Browsershot documentation. Then test your installation by runnning a tinker session (`php artisan tinker`) with the following code: `\Spatie\Browsershot\Browsershot::url('https://google.com')->ignoreHttpsErrors()->save('example.pdf');`. If that simple code triggers errors, please fix your Browsershot / Puppeteer installation before going any further. We've provided a few [troubleshooting tips &amp; tricks](https://github.com/Laravel-Backpack/download-operation/edit/main/readme.md#troubleshooting) at the bottom of this page.

**Step 1.** Install this package via Composer

```
composer require backpack/download-operation
```

**Step 2.** To add a "Download" button next to each entry inside your EntityCrudController and a bulk button at the bottom of the table, use these operations on your EntityCrudController:

```
class InvoiceCrudController extends CrudController
{
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
+    use \Backpack\DownloadOperation\DownloadOperation;
+    use \Backpack\DownloadOperation\BulkDownloadOperation;
```

Please note that `BulkDownloadOperation` is not a "real" operation. It's just a button that points to the normal "Download" operation. So you cannot use `BulkDownloadOperation` without `DownloadOperation`. The inverse is possible, only using `DownloadOperation` without `BulkDownloadOperation`.

**Step 3.** Configure your download operation by defining your fields and settings in `setupDownloadOperation()`

```
    /**
     * Configure what the Download button actually downloads.
     */
    public function setupDownloadOperation()
    {
        // [OPTION 1] - you can manually add your columns:
        CRUD::column('title');

        // [OPTION 2] - since you've probably already defined columns in your List or Show operation, you could do:
        $this->setupListOperation(); // or $this->setupShowOperation();

        // in addition, in case you want to change settings:
        CRUD::set('download.view', 'user.invoice.download'); // default is: crud::show
        CRUD::set('download.format', 'A3'); // default is: A4
        CRUD::set('download.headers', ['Content-Type' => 'application/pdf']); // default is: ['Content-Type' => 'application/pdf']

        // in case you want to configure browsershot instance. more info on Overriding section.
        CRUD::set('download.browsershot', \App\DownloadInvoice::class); // default is: null
    }
```

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

[](#configuration)

### Publish the config file

[](#publish-the-config-file)

You can optionally publish the config file to overwrite the default settings:

```
php artisan vendor:publish --provider="Backpack\DownloadOperation\AddonServiceProvider" --tag=config
```

### Configure the Browsershot instance

[](#configure-the-browsershot-instance)

If you need to change the way the PDF is generated, you can create a new `__invokable()` class. The class should return the `Browsershow` result we will stream to the browser. Here is an example:

```
    // in your EntityCrudController.php
    protected function setupDownloadOperation() {
        // ...
        CRUD::set('download.browsershot', \App\DownloadInvoice::class);
    }

    // create the following file in App\DownloadInvoice.php
    namespace App;

    use Spatie\Browsershot\Browsershot;

    class DownloadInvoice
    {
        public function __invoke($data)
        {
            // check spatie docs for more options
            return Browsershot::html(view($data['view'], $data))
                ->noSandbox()
                ->setChromePath('/usr/bin/google-chrome-stable')
                ->format($data['format'])
                ->pdf();
        }
    }
```

### Configure the download method

[](#configure-the-download-method)

If you need to change the way the file is downloaded, you can create a new `downloadFile()` method in your EntityCrudController. Here is an example:

```
    protected function downloadFile($data)
    {
        return response()->streamDownload(function () use ($data) {
            echo Browsershot::html(view($data['view'], $data))
                ->format($data['format'])
                ->pdf();
        }, $data['filename'], $data['headers']);
    }
```

Changelog
---------

[](#changelog)

Changes are documented here on Github. Please see the [Releases tab](https://github.com/laravel-backpack/download-operation/releases).

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for a todolist and howtos.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Cristian Tabacitu](https://github.com/laravel-backpack)
- [All Contributors](../../contributors)

License
-------

[](#license)

This project was released under MIT, so you can install it on top of any Backpack &amp; Laravel project. Please see the [license file](license.md) for more information.

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

[](#troubleshooting)

This package uses [spatie/browsershot](https://github.com/spatie/browsershot/), which uses Puppetteer, which itself uses a headless Chrome. So... a lot can go wrong during the installation phase. It can either go silky-smooth or be a nightmare. To help you out, here are a few issues we've encountered, and their solutions.

#### How to test if the Puppeteer installation is working

[](#how-to-test-if-the-puppeteer-installation-is-working)

We recommend you run a tinker (`php artisan tinker`) and try the following:

```
use Spatie\Browsershot\Browsershot;

Browsershot::url('https://google.com')->ignoreHttpsErrors()->save('example.pdf');
```

If that triggers errors... the problem is with your Puppeteer installation. Take a hard look at the error message, it might provide steps to fix or clues.

#### Could not find Chromium (rev. 1095492)

[](#could-not-find-chromium-rev-1095492)

We've gotten this error, along the years, for multiple reasons:

- we had to upgrade the node version
- we were not using that node version
- the chache path was indeed incorrect (see below)

#### Cache path is wrong (eg. on MacOS when using Laravel Valet)

[](#cache-path-is-wrong-eg-on-macos-when-using-laravel-valet)

In your error message, see what cache path is being used. Most likely it's trying to use `.cache/puppeteer` inside the PROJECT DIRECTORY. Which is wrong, because it definitely won't find Chrome there. You want it to use the GLOBAL DIRECTORY. To define a cache path for a particular project, you can define a new `.ENV` variable:

```
PUPPETEER_CACHE_DIR="/Users/tabacitu/.cache/puppeteer"

```

You might also need to create that directory and restart your server. After that, it should work.

#### Does not work on M1 Mac (aka. chromium arm64 bug)

[](#does-not-work-on-m1-mac-aka-chromium-arm64-bug)

If you're running an M1 or M2 Mac, you might need to follow [this tutorial](https://linguinecode.com/post/how-to-fix-m1-mac-puppeteer-chromium-arm64-bug).

#### Other problems

[](#other-problems)

We heavily recommend you check Puppeteer's troubleshooting page:

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance76

Regular maintenance activity

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~186 days

Recently: every ~135 days

Total

11

Last Release

132d ago

Major Versions

1.0.1 → 2.0.02022-03-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2073da18c2e24ef792dd3e9aa51d5427a79a7abfd252788e57eeb1007a89f87?d=identicon)[tabacitu](/maintainers/tabacitu)

---

Top Contributors

[![tabacitu](https://avatars.githubusercontent.com/u/1032474?v=4)](https://github.com/tabacitu "tabacitu (21 commits)")[![pxpm](https://avatars.githubusercontent.com/u/7188159?v=4)](https://github.com/pxpm "pxpm (6 commits)")[![TanNhatCMS](https://avatars.githubusercontent.com/u/113796420?v=4)](https://github.com/TanNhatCMS "TanNhatCMS (1 commits)")

---

Tags

laravelbackpackBackpack for LaravelBackpack AddonDownload ImageDownload OperationDownload PDFDownload SnapshotBackpack Download Button

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/backpack-download-operation/health.svg)

```
[![Health](https://phpackages.com/badges/backpack-download-operation/health.svg)](https://phpackages.com/packages/backpack-download-operation)
```

###  Alternatives

[backpack/theme-tabler

UI for Backpack v6 that uses Tabler and Bootstrap v5.

35536.5k](/packages/backpack-theme-tabler)[backpack/activity-log

Activity Log for Backpack

3487.5k1](/packages/backpack-activity-log)[backpack/translation-manager

Translation Manager for Backpack

5118.9k1](/packages/backpack-translation-manager)[backpack/medialibrary-uploaders

Helper functions to save files with spatie media library

1373.3k](/packages/backpack-medialibrary-uploaders)[figlabhq/crud-resource-for-backpack

Build CRUD panels using fluent field definitions.

122.1k](/packages/figlabhq-crud-resource-for-backpack)

PHPackages © 2026

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