PHPackages                             laminblur/filament-pdf-sanitizer - 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. laminblur/filament-pdf-sanitizer

ActiveLibrary

laminblur/filament-pdf-sanitizer
================================

A Filament plugin that automatically sanitizes PDF files by removing JavaScript, forms, and annotations before upload to prevent WAF blocking

1.0.12(2mo ago)0231MITJavaScriptPHP ^8.2CI passing

Since Dec 3Pushed 2mo agoCompare

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

READMEChangelog (10)Dependencies (3)Versions (13)Used By (0)

Filament PDF Sanitizer
======================

[](#filament-pdf-sanitizer)

[![Latest Version](https://camo.githubusercontent.com/a518e774311943c90d860d47b9cd1f14992c57d6cb62d88800af0790c49a8ad5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c616d696e626c75722f66696c616d656e742d7064662d73616e6974697a65723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laminblur/filament-pdf-sanitizer)[![License](https://camo.githubusercontent.com/c090e080484e2a2bc766446291d04437db823929042bf614b26a1643660ddf6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e3f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/b543b06c10a4acae57f00e7e89a1188d9f86dc1349389fe58762b4e4842cf9d2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322532422d626c75653f7374796c653d666c61742d737175617265)](https://php.net)[![Laravel](https://camo.githubusercontent.com/2369448a824338eb65ff21fc8e28cf038285cf42ec376b646c98c1ded5ab8f1f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d313125324225323025374325323031322532422d7265643f7374796c653d666c61742d737175617265)](https://laravel.com)[![Filament](https://camo.githubusercontent.com/d8471abb322e1ce625c7e022fe8ca970e3f56dda8c2f531df55a62942bc2ee43/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f66696c616d656e742d332e782d6f72616e67653f7374796c653d666c61742d737175617265)](https://filamentphp.com)

A Filament plugin that automatically sanitizes PDF files by removing JavaScript, forms, annotations, and embedded scripts before upload. This prevents AWS WAF and other security systems from blocking PDF uploads that contain executable content.

🎯 Problem Solved
----------------

[](#-problem-solved)

When uploading PDFs through Filament's FileUpload component, files containing embedded JavaScript or interactive elements can be blocked by security systems like AWS WAF (Web Application Firewall). This plugin automatically sanitizes PDFs client-side before upload, ensuring they pass security checks while preserving all visual content.

✨ Features
----------

[](#-features)

- 🔒 **Automatic PDF Sanitization** - Removes JavaScript, forms, and annotations from PDFs before upload
- 🚀 **Zero Configuration** - Works out of the box with Filament FileUpload components
- ⚡ **Lazy Loading** - Only loads PDF libraries when file inputs are detected (reduces initial bundle size)
- 🎯 **Transparent** - Works seamlessly with Livewire file uploads without user intervention
- 📦 **Lightweight** - Optimized bundle size with code splitting and dynamic imports
- 🔄 **Smart Caching** - Caches sanitized files to prevent re-processing on retry
- 🛡️ **WAF Compatible** - Prevents AWS WAF and other security systems from blocking uploads
- 📊 **Progress Indicators** - Visual feedback during PDF sanitization
- ⚙️ **Configurable** - Customize quality, scale, file size limits, and more
- 🧹 **Memory Efficient** - Automatic cleanup of canvas elements and memory management
- 🚨 **Error Handling** - Graceful error handling with console logging
- 📏 **File Size Limits** - Configurable maximum file size and page count limits

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 11 or 12
- Filament 3.x
- Node.js dependencies: `jspdf` and `pdfjs-dist` (see [PDF.js version compatibility](#pdfjs-version-compatibility) below)

📦 Installation
--------------

[](#-installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Install the package directly from [Packagist](https://packagist.org/packages/laminblur/filament-pdf-sanitizer):

```
composer require laminblur/filament-pdf-sanitizer
```

### Step 2: Install NPM Dependencies

[](#step-2-install-npm-dependencies)

```
npm install jspdf pdfjs-dist
```

**PDF.js version:** The package ships a PDF.js worker that matches a specific `pdfjs-dist` version. To avoid "API version does not match the Worker version" errors, pin `pdfjs-dist` in your app's `package.json` to the same version as the bundled worker (e.g. `"pdfjs-dist": "5.4.449"`). If you want to use a different or newer `pdfjs-dist`, set `workerPath` to the worker from your installed version (see [Configuration](#configuration-options) and [Troubleshooting](#api-version-does-not-match-the-worker-version)).

### Step 3: Publish Assets

[](#step-3-publish-assets)

```
php artisan vendor:publish --tag=filament-pdf-sanitizer-assets
php artisan vendor:publish --tag=filament-pdf-sanitizer-config
```

> **Note:** The PDF worker file is automatically copied to `public/vendor/filament-pdf-sanitizer/` when the package is installed. If you need to update it, run the publish command again with the `--force` flag. The default worker matches a specific `pdfjs-dist` version; your app's `pdfjs-dist` version must match, or set `workerPath` to your own worker.

### Step 4: Update Vite Config (Optional)

[](#step-4-update-vite-config-optional)

If you want to explicitly include the package assets in your build, add to `vite.config.js`:

```
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
                'resources/css/filament/admin/theme.css',
                'resources/js/vendor/filament-pdf-sanitizer/init.js', // Add this
            ],
            refresh: true,
        }),
    ],
    optimizeDeps: {
        include: ['pdfjs-dist', 'jspdf'],
    },
    build: {
        rollupOptions: {
            output: {
                manualChunks: undefined,
            },
        },
    },
});
```

### Step 5: Rebuild Assets

[](#step-5-rebuild-assets)

```
npm run build
```

🚀 Usage
-------

[](#-usage)

### Basic Usage

[](#basic-usage)

Add the plugin to your Filament panel provider:

```
