How to Add Watermarks to PDF Pages in Laravel Using SnappyPDF

Learn how to add watermarks to all dynamically generated PDF pages in Laravel using SnappyPDF. A step-by-step guide to adding watermarks to your PDFs.

Muhammad Ishaq
Muhammad Ishaq
16 Jul 2025
4 minute read
How to Add Watermarks to PDF Pages in Laravel Using SnappyPDF

Adding watermarks to PDFs is a great way to protect documents, indicate branding, or mark drafts. If you're generating PDFs in Laravel, whether for reports, invoices, or certificates. SnappyPDF offers the flexibility to apply image watermarks across every page with precision.

In this guide, you’ll learn how to use SnappyPDF to add transparent image watermarks to dynamically generated PDF files in Laravel, using Blade views and built-in options for clean, consistent results.

Note: If you haven’t already installed and configured SnappyPDF, follow our detailed setup guide here:
How to Generate Multi-Page PDFs with Header and Footer Using SnappyPDF in Laravel


What You’ll Learn

How to set up Blade views for watermark support

  • Add watermark images to every PDF page

  • Generate clean, multi-page PDFs with headers and margins

  • Pass dynamic data into the view


Blade Views Setup

We’ll create two views:

  • resources/views/pdf/main.blade.php → Main PDF content

  • resources/views/pdf/header.blade.php → Watermark (and optional header)


main.blade.php PDF Content

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <title>PDF with Watermark</title>

    <style>
        body { font-family: sans-serif; margin: 0; padding: 0; }
        .content { margin: 100px 50px; }
        .page-break { page-break-after: always; }
    </style>

</head>

<body>

    <div class="content">
        <h1>Hello, {{ $name }}</h1>
        <p>This is a sample PDF with watermark on every page.</p>
    </div>
 
    <div class="page-break"></div>

    <div class="content">
        <p>page content goes here...</p>
    </div>

</body>

</html>

header.blade.php Watermark Image

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        .watermark {
            width: 100%;
            height: 100%;
            position: fixed;
            top: 30%;
            left: 25%;
            opacity: 0.07;
            text-align: center;
        }

        .watermark img {
            width: 400px;
            height: auto;
            position: absolute;
        }

    </style>
</head>

<body>
    <div class="watermark">
        <img src="{{ public_path('your-logo.png') }}" alt="Watermark" />
    </div>
</body>

</html>

You can replace 'your-logo.png' with any transparent PNG or brand asset you want to use as a watermark.


Generate the PDF with Watermark (Controller)

In your controller:

use Barryvdh\Snappy\Facades\SnappyPdf as SPDF;

public function generatePdf()
{
    $pdf = SPDF::loadView('pdf.main', ['name' => ‘Some Name’])
        ->setPaper('a4')
        ->setOption('margin-top', '40mm') // Space for header
        ->setOption('header-html', view('pdf.header')->render())
        ->setOption('header-spacing', 0);

    return $pdf->download('document-with-watermark.pdf');
}

Add a Route

In routes/web.php:

Route::get('/generate-pdf', [YourController::class, 'generatePdf']);

PDF Options Recap

  • header-html: Injects the watermark view (or any HTML) into every page.

  • margin-top: Reserves vertical space at the top for the header.

  • header-spacing: Controls the spacing between the header and main content.

  • page-break-after: Forces a new page after the specified content (for multi-page layout).


Bonus: Use Dynamic Watermarks

Want to dynamically switch watermarks?

$pdf = SPDF::loadView('pdf.main', ['name' => ‘Some Name’])
    ->setOption('header-html', view('pdf.header', [
        'watermark' => public_path('images/custom-watermark.png')
    ])->render());

Then in header.blade.php:

<img src="{{ $watermark }}" alt="Watermark" />

Conclusion

SnappyPDF is more than just a PDF generator, it gives you powerful layout and styling capabilities with minimal effort. By using header-html, you can easily insert image-based or text-base watermarks across all pages of your document without touching each page manually.

Whether you’re generating certificates, reports, or official documents, adding watermarks enhances authenticity and branding, making SnappyPDF a great fit for production use in Laravel apps.