PHPackages                             shoaib3375/php-doc-exporter - 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. shoaib3375/php-doc-exporter

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

shoaib3375/php-doc-exporter
===========================

All-in-one Laravel document exporter

v1.1.0(4mo ago)12MITPHPPHP ^8.1

Since Feb 20Pushed 2mo agoCompare

[ Source](https://github.com/Shoaib3375/php-doc-exporter)[ Packagist](https://packagist.org/packages/shoaib3375/php-doc-exporter)[ RSS](/packages/shoaib3375-php-doc-exporter/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (5)Used By (0)

PHP Doc Exporter
================

[](#php-doc-exporter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/753592182cd1d339a5cee22ce38309a3591de0661766f52bdcef0293f7f166d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73686f616962333337352f7068702d646f632d6578706f727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shoaib3375/php-doc-exporter)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

An all-in-one PHP/Laravel library to generate professional documents in **PDF, Excel, Word, and CSV** formats with specialized support for **Bangla Unicode** and built-in **API Token Security**.

🚀 Features
----------

[](#-features)

- **Blade Template Support**: Use Laravel Blade views for custom PDF layouts
    - **Bangla Support**: Auto-detects Bangla Unicode and switches to bundled NotoSansBengali font automatically.
    - **Multi-Format**: One interface for 4 major document types.
    - **Secure**: Built-in logic for Main and Safe API tokens for external integrations.
    - **Performant**: Optimized for speed and minimal memory footprint.
    - **API Ready**: Perfect for REST APIs with token-based authentication

---

🛠 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require shoaib3375/php-doc-exporter
```

### Laravel Setup (Optional)

[](#laravel-setup-optional)

The package auto-registers in Laravel. Optionally publish the config:

```
php artisan vendor:publish --provider="Shoaib3375\PhpDocExporter\PhpDocExporterServiceProvider"
```

Then configure tokens in `.env`:

```
PHP_DOC_EXPORTER_MAIN_TOKEN=your-main-token
PHP_DOC_EXPORTER_SAFE_TOKEN=your-safe-token
```

📖 Quick Start
-------------

[](#-quick-start)

### Basic Usage (Plain PHP)

[](#basic-usage-plain-php)

```
use Shoaib3375\PhpDocExporter\DocumentExporter;

$data = [
    ['name' => 'Shoaib', 'age' => 25, 'city' => 'Dhaka'],
    ['name' => 'মাইনুল', 'age' => 30, 'city' => 'Sylhet']
];

$exporter = new DocumentExporter();
$content = $exporter->export('pdf', $data);

// Save to file
file_put_contents('report.pdf', $content);
```

### Laravel Controller Example

[](#laravel-controller-example)

```
use Shoaib3375\PhpDocExporter\DocumentExporter;
use Illuminate\Http\Request;

public function export(Request $request)
{
    $data = [
        ['name' => 'Shoaib', 'age' => 25, 'city' => 'Dhaka'],
        ['name' => 'মাইনুল', 'age' => 30, 'city' => 'Sylhet']
    ];

    $exporter = new DocumentExporter();
    $format = $request->input('format', 'pdf'); // pdf, excel, word, csv

    $content = $exporter->export($format, $data);

    $extension = match($format) {
        'excel' => 'xlsx',
        'word' => 'docx',
        default => $format
    };

    return response($content)
        ->header('Content-Type', $this->getMimeType($format))
        ->header('Content-Disposition', 'attachment; filename="report.' . $extension . '"');
}

private function getMimeType($format) {
    return match($format) {
        'pdf' => 'application/pdf',
        'excel' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'word' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'csv' => 'text/csv',
    };
}
```

### Using Blade Templates (NEW)

[](#using-blade-templates-new)

```
use Shoaib3375\PhpDocExporter\DocumentExporter;

public function exportInvoice(Request $request)
{
    $data = [
        'title' => 'Sales Invoice',
        'invoiceNumber' => 'INV-2024-001',
        'customerName' => 'মোহাম্মদ শোয়েব',
        'items' => [
            ['name' => 'Product A', 'quantity' => 2, 'price' => 500],
            ['name' => 'পণ্য বি', 'quantity' => 1, 'price' => 1000],
        ],
        'total' => 2000
    ];

    $exporter = new DocumentExporter();
    $content = $exporter->exportFromView('pdf', 'invoice', $data, [
        'paper' => 'A4',
        'orientation' => 'portrait'
    ]);

    return response($content)
        ->header('Content-Type', 'application/pdf')
        ->header('Content-Disposition', 'attachment; filename="invoice.pdf"');
}
```

### API with Token Authentication

[](#api-with-token-authentication)

```
Route::middleware('auth:sanctum')->post('/export/invoice', function (Request $request) {
    $token = $request->bearerToken();

    $data = ['title' => 'Invoice', 'items' => [...]];

    $exporter = new DocumentExporter();
    $content = $exporter->exportFromView('pdf', 'invoice', $data, [], $token);

    return response($content)
        ->header('Content-Type', 'application/pdf')
        ->header('Content-Disposition', 'attachment; filename="invoice.pdf"');
});
```

---

🎨 Blade Template Support
------------------------

[](#-blade-template-support)

### Creating a Blade Template

[](#creating-a-blade-template)

Create a view file at `resources/views/invoice.blade.php`:

```

        body { font-family: 'DejaVu Sans', sans-serif; }
        table { width: 100%; border-collapse: collapse; }
        th, td { border: 1px solid #000; padding: 8px; }

    {{ $title }}
    Invoice #{{ $invoiceNumber }}

                Item
                Quantity
                Price

            @foreach($items as $item)

                {{ $item['name'] }}
                {{ $item['quantity'] }}
                {{ $item['price'] }}

            @endforeach

    Total: {{ $total }}

```

### Using the Template

[](#using-the-template)

```
$exporter = new DocumentExporter();
$content = $exporter->exportFromView('pdf', 'invoice', [
    'title' => 'Sales Invoice',
    'invoiceNumber' => 'INV-001',
    'items' => [...],
    'total' => 2000
]);
```

### Benefits

[](#benefits)

- **Custom Layouts**: Design complex documents with full HTML/CSS control
    - **Reusable Templates**: Share templates across your application
    - **Dynamic Content**: Use Blade directives (@if, @foreach, @include)
    - **Bangla Support**: Full Unicode support in templates

---

🎨 Advanced Options
------------------

[](#-advanced-options)

### PDF Customization

[](#pdf-customization)

```
$options = [
    'title' => 'Sales Report',
    'paper' => 'A4',           // A4, Letter, Legal
    'orientation' => 'landscape', // portrait or landscape
    'font' => 'NotoSansBengali' // Optional: override auto-detected font
];

$content = $exporter->export('pdf', $data, $options);
```

### Word/Excel Customization

[](#wordexcel-customization)

```
$options = [
    'title' => 'Monthly Report'
];

$content = $exporter->export('word', $data, $options);
```

### Data Format

[](#data-format)

Use **associative arrays** where keys become column headers:

```
$data = [
    ['name' => 'John', 'email' => 'john@example.com'],
    ['name' => 'জন', 'email' => 'john@example.bd']
];
```

---

🔒 API Token Security (Optional)
-------------------------------

[](#-api-token-security-optional)

### Using Tokens for Protected Exports

[](#using-tokens-for-protected-exports)

```
$exporter = new DocumentExporter();

// Export with token validation
$content = $exporter->export('pdf', $data, [], $apiToken);
// Throws InvalidArgumentException if token is invalid
```

### Custom Token Configuration

[](#custom-token-configuration)

```
use Shoaib3375\PhpDocExporter\Config;

$config = new Config();

// Validate tokens
if ($config->canAccessFullApi($token)) {
    // Full access: create, edit, update
}

if ($config->canAccessSafeApi($token)) {
    // Safe access: export only
}
```

---

🇧🇩 Bangla Unicode Support
-------------------------

[](#-bangla-unicode-support)

All formats support Bangla Unicode **automatically** — no configuration needed.

The package detects Bangla characters in your data and applies the correct font.

### PDF

[](#pdf)

Bangla font (NotoSansBengali) is bundled inside the package — no manual font installation required.

```
$data = [
    ['নাম' => 'শোয়েব', 'বয়স' => '২৫', 'শহর' => 'ঢাকা'],
];
$pdf = $exporter->export('pdf', $data); // font is chosen automatically
```

### Excel / Word / CSV

[](#excel--word--csv)

These formats use Unicode-native libraries and work out of the box.

### Manual font override (optional)

[](#manual-font-override-optional)

If you need a specific font, you can still pass it explicitly:

```
$pdf = $exporter->export('pdf', $data, ['font' => 'Kalpurush']);
```

---

📄 API Reference
---------------

[](#-api-reference)

### `DocumentExporter`

[](#documentexporter)

#### `exportFromView(string $format, string $view, array $data = [], array $options = [], string $token = null): string`

[](#exportfromviewstring-format-string-view-array-data---array-options---string-token--null-string)

Generates PDF from Blade template (Laravel only).

**Parameters:**

- `$format` - Currently only `'pdf'` supported for views
    - `$view` - Blade view name (e.g., `'invoice'` for `resources/views/invoice.blade.php`)
    - `$data` - Data to pass to the Blade view
    - `$options` - Optional settings:
        - `paper` - PDF paper size (A4, Letter, Legal)
        - `orientation` - PDF orientation (portrait, landscape)
        - `font` - PDF font (auto-detected: Bangla → NotoSansBengali, else DejaVu Sans)
    - `$token` - Optional API token for validation

**Returns:** PDF content as string

**Throws:** `InvalidFormatException` or `InvalidTokenException`

---

#### `export(string $format, array $data, array $options = [], string $token = null): string`

[](#exportstring-format-array-data-array-options---string-token--null-string)

Generates document content and returns as string.

**Parameters:**

- `$format` - Format type: `'pdf'`, `'excel'`, `'word'`, `'csv'`
    - `$data` - Associative array of data (keys = headers)
    - `$options` - Optional settings:
        - `title` - Document title
        - `paper` - PDF paper size (A4, Letter, Legal)
        - `orientation` - PDF orientation (portrait, landscape)
        - `font` - PDF font (auto-detected: Bangla → NotoSansBengali, else DejaVu Sans)
    - `$token` - Optional API token for validation

**Returns:** Document content as string

**Throws:** `InvalidArgumentException` for invalid format or token

---

### `Config`

[](#config)

MethodDescription`canAccessFullApi(string $token): bool`Validates main API token`canAccessSafeApi(string $token): bool`Validates safe or main token`getMainApiToken(): string`Returns primary token`getSafeApiToken(): string`Returns secondary token---

📜 License
---------

[](#-license)

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

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance80

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Total

4

Last Release

133d ago

### Community

Maintainers

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

---

Top Contributors

[![Shoaib3375](https://avatars.githubusercontent.com/u/60780232?v=4)](https://github.com/Shoaib3375 "Shoaib3375 (18 commits)")

---

Tags

phplaravelpdfunicodeexcelcsvexporterwordBangla

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shoaib3375-php-doc-exporter/health.svg)

```
[![Health](https://phpackages.com/badges/shoaib3375-php-doc-exporter/health.svg)](https://phpackages.com/packages/shoaib3375-php-doc-exporter)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.9k157.3M892](/packages/maatwebsite-excel)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[phpnt/yii2-export

Yii2 It saves data in xls, csv, word, html, pdf files.

158.9k](/packages/phpnt-yii2-export)

PHPackages © 2026

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