PHPackages                             mikailfaruqali/invoice-template - 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. [Templating &amp; Views](/categories/templating)
4. /
5. mikailfaruqali/invoice-template

ActiveLibrary[Templating &amp; Views](/categories/templating)

mikailfaruqali/invoice-template
===============================

A powerful Laravel package for generating professional PDF invoices with customizable templates. Features advanced header/footer support, multi-language capabilities, and a comprehensive template management system powered by wkhtmltopdf via Snappy PDF generator.

3.3.3(6mo ago)11141↓93.8%MITBladePHP &gt;=7.4

Since Aug 20Pushed 6mo agoCompare

[ Source](https://github.com/mikailfaruqali/invoice-template)[ Packagist](https://packagist.org/packages/mikailfaruqali/invoice-template)[ Docs](https://github.com/mikailfaruqali/invoice-template)[ RSS](/packages/mikailfaruqali-invoice-template/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (5)Versions (50)Used By (0)

Laravel Invoice Template Package
================================

[](#laravel-invoice-template-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d88f3e5a10b276912282b877de8ac805ee9e4f407c81301bf7ca4acc3cdf70ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696b61696c6661727571616c692f696e766f6963652d74656d706c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mikailfaruqali/invoice-template)[![Total Downloads](https://camo.githubusercontent.com/4a4bd51fa2f3778ca7340b85052a382d4394087e6e262f114a32bd34bae63607/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696b61696c6661727571616c692f696e766f6963652d74656d706c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mikailfaruqali/invoice-template)[![License](https://camo.githubusercontent.com/92c82329d826f3159eb71409572d2fa8f300d6069872c3e5dd62eae399365889/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d696b61696c6661727571616c692f696e766f6963652d74656d706c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mikailfaruqali/invoice-template)

A powerful Laravel package for generating professional PDF invoices with customizable templates. Features advanced header/footer support, multi-language capabilities, and a comprehensive template management system powered by wkhtmltopdf via Snappy PDF generator.

Features
--------

[](#features)

### 🎨 **Template Management**

[](#-template-management)

- **Database-driven templates** with full CRUD operations
- **Multi-language support** with locale-based template selection
- **Page-specific templates** using customizable slugs (invoice, receipt, summary, etc.)
- **Visual template editor** with live preview capabilities
- **Password-protected content editing** for security

### 📄 **PDF Generation**

[](#-pdf-generation)

- **Professional PDF output** using wkhtmltopdf engine
- **Customizable headers and footers** with Blade template support
- **Multiple paper sizes** (A4, A5, A3, Letter, Legal)
- **Portrait and landscape orientations**
- **Precise margin control** (top, bottom, left, right)
- **Header/footer spacing configuration**

### 🌐 **Internationalization**

[](#-internationalization)

- **Multi-language template support**
- **RTL/LTR text direction** handling
- **Locale-based template fallback** system
- **Session-based direction configuration**

### ⚙️ **Advanced Configuration**

[](#️-advanced-configuration)

- **Comprehensive PDF options** (DPI, image quality, compression, etc.)
- **Custom font support** with font directory configuration
- **Flexible middleware** for route protection
- **Configurable table names** and route prefixes
- **Cross-platform binary support** (Windows/Linux)

### 🔒 **Security**

[](#-security)

- **Password protection** for template content modifications
- **Middleware-based access control**
- **Secure file generation** with unique filenames
- **CSRF protection** on all forms

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

[](#installation)

### Requirements

[](#requirements)

- PHP &gt;= 7.4
- Laravel &gt;= 5.0
- wkhtmltopdf binary installed on your system

### Step 1: Install the Package

[](#step-1-install-the-package)

```
composer require mikailfaruqali/invoice-template
```

### Step 2: Install wkhtmltopdf

[](#step-2-install-wkhtmltopdf)

#### Windows

[](#windows)

Download and install wkhtmltopdf from [official website](https://wkhtmltopdf.org/downloads.html)

#### Ubuntu/Debian

[](#ubuntudebian)

```
sudo apt-get update
sudo apt-get install wkhtmltopdf
```

#### CentOS/RHEL

[](#centosrhel)

```
sudo yum install wkhtmltopdf
```

### Step 3: Publish Assets

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

```
php artisan vendor:publish --tag=snawbar-invoice-template-assets
```

This will publish:

- Configuration file: `config/snawbar-invoice-template.php`
- Migration file: `database/migrations/2025_08_20_000001_create_invoice_templates_table.php`

### Step 4: Run Migrations

[](#step-4-run-migrations)

```
php artisan migrate
```

### Step 5: Configure wkhtmltopdf Binary Path

[](#step-5-configure-wkhtmltopdf-binary-path)

Edit `config/snawbar-invoice-template.php`:

```
'binary' => [
    'windows' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"',
    'linux' => '/usr/local/bin/wkhtmltopdf',  // Adjust path as needed
],
```

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

[](#configuration)

### Basic Configuration

[](#basic-configuration)

```
// config/snawbar-invoice-template.php

return [
    // Page slugs for template organization
    'page-slugs' => ['invoice', 'receipt', 'quotation', 'statement'],

    // Security password for content editing
    'password' => 'your-secure-password',

    // Route configuration
    'route-prefix' => 'invoice-templates',
    'middleware' => ['web', 'auth'],

    // Database table name
    'table' => 'invoice_templates',

    // PDF generation options
    'options' => [
        'encoding' => 'UTF-8',
        'enable-local-file-access' => true,
        'dpi' => 150,
        'image-quality' => 75,
        // ... more options
    ],
];
```

### Advanced PDF Options

[](#advanced-pdf-options)

```
'options' => [
    'encoding' => 'UTF-8',
    'enable-local-file-access' => true,
    'disable-javascript' => true,
    'disable-plugins' => true,
    'print-media-type' => true,
    'no-background' => false,
    'grayscale' => false,
    'dpi' => 150,
    'image-dpi' => 150,
    'image-quality' => 75,
    'minimum-font-size' => 8,
    'zoom' => 1.0,
    'viewport-size' => '1024x768',
],
```

Usage
-----

[](#usage)

### Template Management Interface

[](#template-management-interface)

Access the template management interface at:

```
/invoice-templates

```

The interface provides:

- Create, edit, and delete templates
- Live preview of template changes
- Multi-language template management
- Page slug organization
- Margin and spacing configuration

### Basic PDF Generation

[](#basic-pdf-generation)

```
use Snawbar\InvoiceTemplate\InvoiceTemplate;

// Generate PDF for default template
$pdf = InvoiceTemplate::make()
    ->renderContent('your-invoice-view')
    ->contentData(['invoice' => $invoice])
    ->inline(); // Download immediately

// Save PDF to storage
$filePath = InvoiceTemplate::make()
    ->renderContent('your-invoice-view')
    ->contentData(['invoice' => $invoice])
    ->save();
```

### Page-Specific Templates

[](#page-specific-templates)

```
// Use specific page template
$pdf = InvoiceTemplate::make('invoice')
    ->renderContent('invoices.template')
    ->contentData(['invoice' => $invoice])
    ->inline();

// Use receipt template
$pdf = InvoiceTemplate::make('receipt')
    ->renderContent('receipts.template')
    ->contentData(['receipt' => $receipt])
    ->inline();
```

### Advanced Usage with Headers and Footers

[](#advanced-usage-with-headers-and-footers)

```
$pdf = InvoiceTemplate::make('invoice')
    ->renderContent('invoices.content')
    ->contentData(['invoice' => $invoice])
    ->renderHeader('invoices.header')
    ->headerData(['company' => $company])
    ->renderFooter('invoices.footer')
    ->footerData(['terms' => $terms])
    ->setOption('margin-top', 60)
    ->setOption('margin-bottom', 40)
    ->inline();
```

### Custom PDF Options

[](#custom-pdf-options)

```
$pdf = InvoiceTemplate::make()
    ->renderContent('your-view')
    ->setOptions([
        'page-size' => 'A4',
        'orientation' => 'portrait',
        'margin-top' => 50,
        'margin-bottom' => 30,
        'dpi' => 300
    ])
    ->inline();
```

### Working with Multiple Languages

[](#working-with-multiple-languages)

```
// Template selection priority:
// 1. Specific page + current locale
// 2. Specific page + wildcard locale (*)
// 3. Wildcard page (*) + current locale
// 4. Wildcard page (*) + wildcard locale (*)

// Set locale before generating
app()->setLocale('ar');

$pdf = InvoiceTemplate::make('invoice')
    ->renderContent('invoices.arabic')
    ->contentData(['invoice' => $invoice])
    ->inline();
```

### Programmatic Template Creation

[](#programmatic-template-creation)

```
use Snawbar\InvoiceTemplate\InvoiceTemplate;

// Create default template
InvoiceTemplate::createDefault(['invoice'], [
    'header' => '{{ $company->name }}',
    'content' => 'Invoice content here',
    'footer' => 'Thank you for your business',
    'lang' => 'en',
    'paper_size' => 'A4',
    'orientation' => 'portrait'
]);
```

### Template Data Variables

[](#template-data-variables)

Templates have access to default variables:

```
{{-- Available in all templates --}}
{{ $marginTop }}
{{ $marginRight }}
{{ $marginLeft }}
{{ $marginBottom }}
{{ $headerSpace }}
{{ $footerSpace }}
{{ $pageSize }}
{{ $orientation }}

{{-- Your custom data --}}
{{ $invoice->number }}
{{ $company->name }}
```

Template Examples
-----------------

[](#template-examples)

### Invoice Header Template

[](#invoice-header-template)

```

    {{ $company->name }}
    {{ $company->address }}
    Phone: {{ $company->phone }} | Email: {{ $company->email }}

```

### Invoice Content Template

[](#invoice-content-template)

```

    Invoice #{{ $invoice->number }}

        Bill To:
        {{ $invoice->customer->name }}
        {{ $invoice->customer->address }}

                Item
                Qty
                Price
                Total

            @foreach($invoice->items as $item)

                {{ $item->description }}
                {{ $item->quantity }}
                ${{ number_format($item->price, 2) }}
                ${{ number_format($item->total, 2) }}

            @endforeach

                Total:
                ${{ number_format($invoice->total, 2) }}

```

### Invoice Footer Template

[](#invoice-footer-template)

```

    Thank you for your business!
    Questions? Contact us at {{ $company->email }} or {{ $company->phone }}
    Page {PAGENO} of {TOPAGE}

```

API Endpoints
-------------

[](#api-endpoints)

The package provides RESTful API endpoints:

MethodURIActionDescriptionGET`/invoice-templates`indexTemplate management interfaceGET`/invoice-templates/get-data`getDataGet all templates (JSON)POST`/invoice-templates/store`storeCreate new templatePUT`/invoice-templates/update/{id}`updateUpdate existing templateDELETE`/invoice-templates/delete/{id}`destroyDelete template### API Usage Examples

[](#api-usage-examples)

```
// Get all templates
fetch('/invoice-templates/get-data')
    .then(response => response.json())
    .then(templates => console.log(templates));

// Create new template
fetch('/invoice-templates/store', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
    },
    body: JSON.stringify({
        page: ['invoice'],
        lang: 'en',
        header: 'Header',
        content: 'Content',
        footer: 'Footer',
        paper_size: 'A4',
        orientation: 'portrait',
        password: 'your-password'
    })
});
```

Database Schema
---------------

[](#database-schema)

The package creates a `invoice_templates` table with the following structure:

```
CREATE TABLE `invoice_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `page` json NOT NULL,                    -- Page slugs (JSON array)
  `header` longtext,                       -- Header template content
  `content` longtext,                      -- Main content template
  `footer` longtext,                       -- Footer template content
  `logo` text,                            -- Logo path/URL
  `margin_top` double DEFAULT 0,          -- Top margin (mm)
  `margin_bottom` double DEFAULT 0,       -- Bottom margin (mm)
  `margin_left` double DEFAULT 0,         -- Left margin (mm)
  `margin_right` double DEFAULT 0,        -- Right margin (mm)
  `header_space` double DEFAULT 0,        -- Header spacing (mm)
  `footer_space` double DEFAULT 0,        -- Footer spacing (mm)
  `orientation` enum('portrait','landscape') DEFAULT 'portrait',
  `paper_size` enum('A4','A5','A3','letter','legal') DEFAULT 'A4',
  `lang` varchar(255) DEFAULT 'en',       -- Language code
  `disabled_smart_shrinking` tinyint(1) DEFAULT 0,
  `disable_header` tinyint(1) DEFAULT 0,  -- Disable header rendering
  `disable_footer` tinyint(1) DEFAULT 0,  -- Disable footer rendering
  `is_active` tinyint(1) DEFAULT 1,       -- Template active status
  PRIMARY KEY (`id`)
);
```

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

[](#troubleshooting)

### Common Issues

[](#common-issues)

#### 1. wkhtmltopdf not found

[](#1-wkhtmltopdf-not-found)

```
Error: The exit code was not zero: 127

```

**Solution:** Ensure wkhtmltopdf is installed and the binary path is correctly configured.

#### 2. Permission denied when saving PDFs

[](#2-permission-denied-when-saving-pdfs)

```
Error: Permission denied

```

**Solution:** Ensure the `public/files` directory is writable:

```
chmod -R 755 public/files
```

#### 3. Template not found

[](#3-template-not-found)

```
Error: No query results for model

```

**Solution:** Create a default template or ensure templates exist for your page slugs.

#### 4. CSRF token mismatch

[](#4-csrf-token-mismatch)

```
Error: 419 Page Expired

```

**Solution:** Ensure CSRF token is included in AJAX requests:

```
axios.defaults.headers.common['X-CSRF-TOKEN'] =
    document.querySelector('meta[name="csrf-token"]').getAttribute('content');
```

### Performance Optimization

[](#performance-optimization)

1. **Use template caching** for frequently used templates
2. **Optimize images** before including in templates
3. **Minimize CSS and HTML** in templates
4. **Use appropriate DPI settings** based on your needs

Security Considerations
-----------------------

[](#security-considerations)

1. **Always validate input** when creating templates programmatically
2. **Use password protection** for content editing in production
3. **Sanitize user input** in template content
4. **Restrict access** using appropriate middleware
5. **Validate file paths** when working with logos and assets

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

### Development Setup

[](#development-setup)

1. Clone the repository
2. Install dependencies: `composer install`
3. Run tests: `composer test`
4. Check code style: `composer pint`

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Mikail Faruq Ali](https://github.com/mikailfaruqali)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Support
-------

[](#support)

If you find this package helpful, please consider:

- ⭐ Starring the repository
- 🐛 Reporting bugs
- 💡 Suggesting new features
- 📖 Improving documentation

---

**Built with ❤️ for the Laravel community**

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

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 ~3 days

Recently: every ~26 days

Total

49

Last Release

188d ago

Major Versions

1.2.2 → 2.0.02025-08-21

2.9.0 → 3.0.02025-08-28

### Community

Maintainers

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

---

Top Contributors

[![mikailfaruqali](https://avatars.githubusercontent.com/u/77926586?v=4)](https://github.com/mikailfaruqali "mikailfaruqali (77 commits)")

---

Tags

laravelpdfwkhtmltopdftemplatesnappyinvoicepdf-generationinvoice-generator

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mikailfaruqali-invoice-template/health.svg)

```
[![Health](https://phpackages.com/badges/mikailfaruqali-invoice-template/health.svg)](https://phpackages.com/packages/mikailfaruqali-invoice-template)
```

###  Alternatives

[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k26.5M51](/packages/barryvdh-laravel-snappy)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

725173.2k14](/packages/tallstackui-tallstackui)[duncan3dc/blade

Use Laravel Blade templates without the full Laravel framework

160507.5k26](/packages/duncan3dc-blade)

PHPackages © 2026

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