PHPackages                             omaralalwi/gpdf - 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. omaralalwi/gpdf

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

omaralalwi/gpdf
===============

Custom PDF wrapper supporting Arabic language

1.0.7(1y ago)15521.1k↓63.6%15[2 issues](https://github.com/omaralalwi/Gpdf/issues)[1 PRs](https://github.com/omaralalwi/Gpdf/pulls)MITPHPPHP ^8.1|^8.2|^8.3CI passing

Since May 26Pushed 6d ago1 watchersCompare

[ Source](https://github.com/omaralalwi/Gpdf)[ Packagist](https://packagist.org/packages/omaralalwi/gpdf)[ Docs](https://github.com/omaralalwi/gpdf)[ RSS](/packages/omaralalwi-gpdf/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (4)Versions (17)Used By (0)

GPDF: Multilingual &amp; Arabic PDF Generator for PHP/Laravel Applications
==========================================================================

[](#gpdf-multilingual--arabic-pdf-generator-for-phplaravel-applications)

[![GitHub Release](https://camo.githubusercontent.com/9a3c59c5417bea6014108997e434561dfe555b5aa57ce96636ead5da5cf0b292/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6f6d6172616c616c77692f477064663f7374796c653d666f722d7468652d626164676526696e636c7564655f70726572656c6561736573)](https://github.com/omaralalwi/Gpdf/releases)[![Total Downloads](https://camo.githubusercontent.com/0fc5f235567cfc026dfc8906ebba8e00104fb27db7595226eee62115eceda086/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6d6172616c616c77692f677064663f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/omaralalwi/gpdf)[![GitHub Stars](https://camo.githubusercontent.com/5763c0e28fb3575ffaa29f9f4615ed6674831d50dfcd33387d3ae6fad7d4e7cd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6f6d6172616c616c77692f477064663f7374796c653d666f722d7468652d6261646765)](https://github.com/omaralalwi/Gpdf/stargazers)[![PHP Version](https://camo.githubusercontent.com/69e9bf4f9d08488cd52e8fefecc512764fd1ff04f3f16fa94d6c8066b8d106ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f6d6172616c616c77692f677064663f7374796c653d666f722d7468652d6261646765)](https://php.net)[![License](https://camo.githubusercontent.com/738044a1fb098a29472ce49e0051e3ae90cff95cb0b61cb1d071d1aef73847bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6d6172616c616c77692f477064663f7374796c653d666f722d7468652d6261646765)](https://opensource.org/licenses/MIT)

 [ ![GPDF: Arabic PDF Generator with S3 Storage | PHP/Laravel Package](https://raw.githubusercontent.com/omaralalwi/Gpdf/master/public/images/gpdf-banner-bg.jpg) ](https://github.com/omaralalwi/Gpdf)

**GPDF** is a PHP/Laravel package for generating **Arabic, RTL, and multilingual PDFs** with native support for 17 built-in Arabic fonts, S3 cloud storage, and enterprise-ready features. Built as a DomPDF extension, it solves Arabic rendering issues while adding modern capabilities for documents, invoices, and reports.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Important Note](#important-note)
- [Publish Resources](#publish-resources)
- [Publish Config](#publish-config-file)
- [Usage with Laravel](#usage-with-laravel)
    - [Using the Gpdf Facade](#using-the-gpdf-facade)
    - [Using Dependency Injection](#using-dependency-injection)
    - [Stream Generated PDF Files](#stream-generated-pdf-files-1)
    - [Storing Generated PDF Files](#storing-generated-pdf-files)
- [Usage with Native PHP Apps](#usage-with-native-php-apps)
    - [Basic Usage](#basic-usage)
    - [Stream Generated PDF Files](#stream-generated-pdf-files)
    - [Store Files to Local](#store-files-to-local)
    - [Store Files to S3](#store-files-to-s3)
- [Supported Fonts](#supported-fonts)
    - [Support for Arabic](#support-for-arabic)
    - [Installing New Fonts](#installing-new-fonts)
- [Install Custom Fonts](#installing-custom-fonts)
- [Features](#features)
- [Thanks](#thanks)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributors](#contributors-)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

---

Requirements
------------

[](#requirements)

- PHP version 8.1 or higher
- DOM extension
- MBString extension
- php-font-lib
- php-svg-lib

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

[](#installation)

```
composer require omaralalwi/gpdf
```

### IMPORTANT NOTE:

[](#important-note)

if you have old version with some issues, please Do following :-

- delete old config file.
- delete package from composer file.
- re-install package.
- publish config file again.
- then delete config cache.

Publish Resources
-----------------

[](#publish-resources)

After installation, publish the config and fonts resources by running the following commands in the root project path:

```
php vendor/omaralalwi/gpdf/scripts/publish_fonts.php
```

> ⚠️ **Important Notes:**
>
> - This step **must be executed in production environments** as well — otherwise, the package will not function properly (fonts will be missing).
> - If you can not run scripts in production, you can **manually copy the `public/vendor/gpdf` folder** to your production environment.
> - Ensure the `public/vendor/gpdf` folder is **writable** and publicly accessible by the web server.

---

Publish Config File
-------------------

[](#publish-config-file)

```
php vendor/omaralalwi/gpdf/scripts/publish_config.php
```

\*\*Note: You must add generated files to git by `git add public/vendor/gpdf/fonts/*.* -f` to ensure the fonts added to production | or run publish command again in production.

---

**Note for Publish Issues:** If you encounter any issues while publishing, manually copy the `vendor/omaralalwi/gpdf/assets/fonts` folder to `public/vendor/gpdf` and ensure the fonts are in `public/vendor/gpdf/fonts`. Also, copy `vendor/omaralalwi/gpdf/config/gpdf.php` to the `/config` folder in the root path.

---

Usage with Laravel
------------------

[](#usage-with-laravel)

### Using the Gpdf Facade

[](#using-the-gpdf-facade)

```
use Omaralalwi\Gpdf\Facade\Gpdf as GpdfFacade;

public function generatePdf()
{
    $html = view('pdf.example-1')->render();
    $pdfContent = GpdfFacade::generate($html);
    return response($pdfContent, 200, ['Content-Type' => 'application/pdf']);
}
```

### Using Dependency Injection

[](#using-dependency-injection)

```
use Omaralalwi\Gpdf\Gpdf;

public function generateSecondWayPdf(Gpdf $gpdf)
{
    $html = view('pdf.example-2')->render();
    $pdfFile = $gpdf->generate($html);
    return response($pdfFile, 200, ['Content-Type' => 'application/pdf']);
}
```

### Stream Generated PDF Files

[](#stream-generated-pdf-files)

Stream a PDF directly to the browser using `generateWithStream`:

```
// by default it store files to local driver (path should in public path).
public function generateAndStream()
{
    $html = view('pdf.example-2')->render();
    $gpdf = app(Gpdf::class);
    $gpdf->generateWithStream($html, 'test-streamed-pdf', true);
    return response(null, 200, ['Content-Type' => 'application/pdf']);
}
```

### Storing Generated PDF Files

[](#storing-generated-pdf-files)

#### Store Files To local

[](#store-files-to-local)

Save a PDF to storage using `generateWithStore`:

**Note** By default it store files to local driver (ensure that: the store path is access able for read and write).

please see [generateWithStore params](#generateWithStore-params) .

```
public function generateAndStore()
{
    $html = view('pdf.example-2')->render();
    $gpdf = app(Gpdf::class);
    $storePath = storage_path('app/downloads/users/');
    $gpdf->generateWithStore($html, $storePath, 'test-stored-pdf-file', true, false); // ssl verify should be true in production .
    return $file['ObjectURL']; // return file url as string , to store in db or do any action
}
// may be you will face problems with stream in local, so you can disable ssl verify in local, but should enable it in production.
```

#### Store Files To S3

[](#store-files-to-s3)

same to store in local, just replace local path with bucket name, and replace `generateWithStore` with `generateWithStoreToS3` .

**Note** Ensure you setup s3 configs in config file.

```
    public function generateAndStoreToS3()
    {
        $data = $this->getDynamicParams();
        $html = view('pdf.example-2',$data)->render();
        $gpdf = app(Gpdf::class);
        $bucketName = 'your_s3_bucket_name'; // should be read abel and write able .
        $file = $gpdf->generateWithStoreToS3($html, $bucketName, 'test-store-pdf-fle', true, true); // with s36 the ssl verify will work in local or production (always secure).
        return $file['ObjectURL']; // return file url as string , to store in db or do any action
    }
```

#### Generate Advance With Fixed Header

[](#generate-advance-with-fixed-header)

please see [this example](https://github.com/omaralalwi/Gpdf-Laravel-Demo/blob/0f041e7cf9030f48e2a35ce6d22e8fac5db98c48/app/Http/Controllers/GpdfController.php#L132C1-L133C1) if you need to add fixed header to all pages

### [Demo Laravel App](https://github.com/omaralalwi/Gpdf-Laravel-Demo)

[](#demo-laravel-app)

this Demo Laravel app contain more detailed examples and cases.

---

Usage with Native PHP Apps
--------------------------

[](#usage-with-native-php-apps)

After installing the package and publishing resources, include `autoload.php` and use the `Gpdf` class.

### Basic Usage

[](#basic-usage)

```
require_once __DIR__ . '/vendor/autoload.php';

use Omaralalwi\Gpdf\Gpdf;
use Omaralalwi\Gpdf\GpdfConfig;

$htmlFile = __DIR__ . '/contents/example-1.html';
$content = file_get_contents($htmlFile);
$gpdfConfigFile = require_once 'config/gpdf.php';

$config = new GpdfConfig($gpdfConfigFile);
$gpdf = new Gpdf($config);
$pdfContent = $gpdf->generate($content);

header('Content-Type: application/pdf');
echo $pdfContent;
```

**Note:** Customize the settings file as needed.

### Stream Generated PDF Files

[](#stream-generated-pdf-files-1)

Stream a PDF directly to the browser using `generateWithStream`:

```
require_once __DIR__ . '/vendor/autoload.php';

use Omaralalwi\Gpdf\Gpdf;
use Omaralalwi\Gpdf\GpdfConfig;

$htmlFile = __DIR__ . '/contents/example-1.html';
$content = file_get_contents($htmlFile);

$gpdfConfigFile = require_once 'config/gpdf.php';
$config = new GpdfConfig($gpdfConfigFile);

$gpdf = new Gpdf($config);
$pdfContent = $gpdf->generateWithStream($content, 'demo-file-name', true);

header('Content-Type: application/pdf');
echo $pdfContent;
```

#### Store Files To Local

[](#store-files-to-local-1)

Save a PDF files to local storage using `generateWithStore`:

**Note** By default it store files to local driver.

```
