PHPackages                             nurdin73/pdf-stamper - 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. nurdin73/pdf-stamper

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

nurdin73/pdf-stamper
====================

Laravel PDF stamping and watermarking with TCPDF &amp; FPDI

01PHP

Since Dec 18Pushed 4mo agoCompare

[ Source](https://github.com/nurdin73/pdf-stamper)[ Packagist](https://packagist.org/packages/nurdin73/pdf-stamper)[ RSS](/packages/nurdin73-pdf-stamper/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PdfStamper
==========

[](#pdfstamper)

PdfStamper is a Laravel package for **stamping, watermarking, and securing PDFs** using TCPDF + FPDI.

Designed specifically for:

- Legal Documents
- Approval Workflows
- ERP / Internal Systems
- Secure Document Distribution

---

✨ Key Features
--------------

[](#-key-features)

- **Stamping:**
    - Text (Plain)
    - HTML (`writeHTMLCell`)
    - Images (PNG/JPG)
    - Precise positioning (X, Y in mm)
    - Custom rotation &amp; colors
- **Watermarking:**
    - Text or Image
    - Flexible positions: `center`, `top`, `bottom`, `left`, `right`
    - Layering: `under` (behind content) or `over` (on top of content)
    - Opacity control (transparency)
- **Security:**
    - PDF Password protection (Optional)
    - File-level encryption (Optional)
- **Developer Friendly:**
    - Fluent API
    - Safe for loops using `resetInstance()`
    - Centralized configuration via `applyConfig()`

---

🔧 Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 8.x
- PHP Extensions: `mbstring`, `gd`

---

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

[](#-installation)

Install the package via Composer:

```
composer require nurdin73/pdf-stamper
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=pdf-stamper-config
```

---

⚙️ Configuration
----------------

[](#️-configuration)

Configuration is available at `config/pdf-stamper.php`:

```
return [
    'unit' => 'mm',
    'default_font' => 'helvetica',
    'default_font_size' => 12,
];
```

---

🚀 Basic Usage
-------------

[](#-basic-usage)

### 1. Text Stamping

[](#1-text-stamping)

```
use PdfStamper;

PdfStamper::resetInstance()
    ->fromFile($source)
    ->stampText('APPROVED', 100, 200, [
        'font_size' => 14,
        'rotate' => 30,
        'color' => '#008000', // Hex string or RGB array: [0, 128, 0]
    ])
    ->save($output);
```

### 2. HTML Stamping

[](#2-html-stamping)

```
PdfStamper::resetInstance()
    ->fromFile($source)
    ->stampHtml('PAID', 80, 150)
    ->save($output);
```

### 3. Image Stamping

[](#3-image-stamping)

```
PdfStamper::resetInstance()
    ->fromFile($source)
    ->stampImage(storage_path('logo.png'), 50, 50, [
        'width' => 40,
        'height' => 40,
    ])
    ->save($output);
```

### 4. Watermarking

[](#4-watermarking)

```
PdfStamper::resetInstance()
    ->fromFile($source)
    ->watermarkText('CONFIDENTIAL', [
        'position' => 'center',
        'rotate' => 45,
        'opacity' => 0.15,
        'color' => '#FF0000',
        'layer' => 'under',
    ])
    ->save($output);
```

### 5. Decrypt File (Optional)

[](#5-decrypt-file-optional)

```
use PdfStamper;

PdfStamper::decryptFile(
    storage_path('secure/encrypted.pdf'),
    'my-secret-key',
    storage_path('temp/decrypted.pdf')
);
```

### 6. Add Metadata to PDF

[](#6-add-metadata-to-pdf)

```
PdfStamper::resetInstance()
    ->fromFile($source)
    ->addMetadata([
        'Title' => 'Document Title',
        'Author' => 'Author Name',
        'Subject' => 'Document Subject',
        'Keywords' => 'keyword1, keyword2',
    ])
    ->save($output);
```

### 7. Add Custom Metadata to PDF

[](#7-add-custom-metadata-to-pdf)

```
PdfStamper::resetInstance()
    ->fromFile($source)
    ->addCustomMetadata([
        'custom_key' => 'custom_value',
    ])
    ->save($output);
```

---

🔁 Single Source of Truth (`applyConfig`)
----------------------------------------

[](#-single-source-of-truth-applyconfig)

Use `applyConfig()` to synchronize data from frontend/database directly with the stamping process.

```
$config = [
    'stamp' => [
        'type' => 'text',
        'value' => 'APPROVED',
        'x' => 120,
        'y' => 200,
        'page' => 1,
        'options' => [
            'font_size' => 14,
            'rotate' => 30,
            'color' => '#008000',
        ],
    ],
    'watermark' => [
        'text' => 'CONFIDENTIAL',
        'position' => 'center',
        'rotate' => 45,
        'opacity' => 0.15,
    ],
];

PdfStamper::resetInstance()
    ->fromFile($source)
    ->applyConfig($config)
    ->save($output);
```

---

🔐 Security (Optional)
---------------------

[](#-security-optional)

### PDF Password

[](#pdf-password)

Restrict PDF access via opening password.

```
->encryptPdf('viewer-password')
```

### Encrypt File (Optional)

[](#encrypt-file-optional)

```
->encryptFileWithKey('my-secret-key')
```

---

🔍 Preview vs Final Flow
-----------------------

[](#-preview-vs-final-flow)

StageDescription**Preview**Generates temporary PDF without encryption for visual validation.**Final**Regenerates from original source, applies security/encryption, immutable.> **Best Practice:** Always regenerate the file from the original source for the Final stage. Never use a Preview output as the base for a Final file.

---

📐 Coordinate Tips (Frontend to Backend)
---------------------------------------

[](#-coordinate-tips-frontend-to-backend)

Frontend typically uses Pixels (px), while PDF uses Millimeters (mm). Use the following formula for conversion:

**Formula:** `mm = px × 25.4 / 96`

**JavaScript Example:**

```
function pxToMm(px) {
  return (px * 25.4) / 96;
}
```

---

⚠️ Important Notes
------------------

[](#️-important-notes)

1. **Reset Instance:** Always call `resetInstance()` before starting a new stamping process.
2. **Looping:** Do not reuse the same instance inside loops or queues without resetting.
3. **Preview File Management:**
    - Use randomized filenames.
    - Set a short TTL (Time To Live).
    - Store in non-public storage if possible.

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance51

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

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.

### Community

Maintainers

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

### Embed Badge

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

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

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.3k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

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

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

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