PHPackages                             khmer-pdf/laravel-kh-pdf - 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. khmer-pdf/laravel-kh-pdf

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

khmer-pdf/laravel-kh-pdf
========================

A simple Laravel package for supporting Khmer font in PDFs using mPdf.

v1.0.3(4mo ago)31.1k↓45%1MITPHPPHP ^8.0CI passing

Since Nov 11Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Duch-Nuon/laravel-kh-pdf)[ Packagist](https://packagist.org/packages/khmer-pdf/laravel-kh-pdf)[ Docs](https://github.com/Duch-Nuon/laravel-kh-pdf)[ RSS](/packages/khmer-pdf-laravel-kh-pdf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

laravel-kh-pdf
==============

[](#laravel-kh-pdf)

[![Latest Stable Version](https://camo.githubusercontent.com/7dc0d76064146aa7287683b458d04d681a70bda8d9eef1b855e7675ecff7feb7/68747470733a2f2f706f7365722e707567782e6f72672f6b686d65722d7064662f6c61726176656c2d6b682d7064662f762f737461626c65)](https://packagist.org/packages/khmer-pdf/laravel-kh-pdf)[![Total Downloads](https://camo.githubusercontent.com/44d0a03fe4c6fe35f270aa3919708458ef4fbcc0187e45d6651307733a0ff036/68747470733a2f2f706f7365722e707567782e6f72672f6b686d65722d7064662f6c61726176656c2d6b682d7064662f646f776e6c6f616473)](https://packagist.org/packages/khmer-pdf/laravel-kh-pdf)[![License](https://camo.githubusercontent.com/797b48a03bb41ea4d084ee093c4e6b23344f09c9549dfbc9e2f52be120230e24/68747470733a2f2f706f7365722e707567782e6f72672f6b686d65722d7064662f6c61726176656c2d6b682d7064662f6c6963656e7365)](https://choosealicense.com/licenses/mit/)

Laravel PDF with Khmer Font Support using mPDF.

Laravel Khmer PDF
=================

[](#laravel-khmer-pdf)

Laravel Khmer PDF is a package designed to simplify PDF generation in Laravel with built-in support for Khmer fonts. It integrates seamlessly with mPDF to create professional-looking PDFs.

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

[](#installation)

Install the package via Composer:

```
composer require khmer-pdf/laravel-kh-pdf
```

Publish the configuration file:

```
php artisan vendor:publish --tag=khPdf
```

This will create a `config/khPdf.php` file where you can customize font settings and mPDF configurations.

Usage
-----

[](#usage)

### Run command to generate demo

[](#run-command-to-generate-demo)

```
php artisan khPdf:demo
```

### Follow the route url

[](#follow-the-route-url)

```
php artisan serve
```

```
http://localhost:8000/kh-pdf-test
```

### Basic PDF Generation

[](#basic-pdf-generation)

Use the `PdfKh` facade to generate PDFs:

```
use KhmerPdf\LaravelKhPdf\Facades\PdfKh;

class PdfController extends Controller
{
    public function generatePdf()
    {
        $html = view('pdf.template', ['title' => 'សួស្តី ពិភពលោក!'])->render();
        return PdfKh::loadHtml($html)->download('khmer_document.pdf');
    }
}
```

Methods
-------

[](#methods)

The trait provides the following methods:

MethodDescriptionExample`loadHtml($html)`Sets the HTML content for the PDF.`PdfKh::loadHtml(view('pdf.template')->render());``download($filename)`Prompts the browser to download the generated PDF.`PdfKh::download('file.pdf');``stream($filename)`Displays the PDF directly in the browser.`PdfKh::stream('file.pdf');``save($path, $disk)`Saves the PDF to the specified storage disk.`PdfKh::save('pdfs/report.pdf', 'public');``addMPdfConfig($config)`Adds custom mPDF configuration settings.`PdfKh::addMPdfConfig(['mode' => 'utf-8', 'format' => 'A4-L']);``watermarkText($text, $opacity, $font, $size, $angle, $color, $config)`Adds a text watermark to the PDF.`PdfKh::watermarkText('Confidential', 0.2, 'khmeros', 100, 45, '#FF0000', []);``watermarkImage($path, $size, $position, $opacity, $behindContent, $config)`Adds an image watermark to the PDF.`PdfKh::watermarkImage('path/to/image.png', 'p', 'p', 1, false, []);``writeBarcode($code, $horizontal, $vertical, $showIsbn, $size, $border)`Writes a barcode in the PDF.`PdfKh::writeBarcode('123456789', 10, 10, true, 1, true);`### Examples

[](#examples)

`template.blade.php`

```
>

    Document

        p{
            font-size: 25px;
            /* font-family: 'battambang';
            font-weight: bold; */

            font-family: 'khmermuol';
        }

    សួស្តី ​ពិភពលោក ! Hello World

```

#### Adding custom mPDF Config

[](#adding-custom-mpdf-config)

You can configure mPDF settings using the `addMPdfConfig` method:

```
public function generateCustomPdf()
{
    $html = view('pdf.template', ['title' => 'Custom PDF'])->render();
    PdfKh::loadHtml($html)->addMPdfConfig([
        'mode' => 'utf-8',
        'format' => 'A4-L',
        'margin_top' => 10,
        'margin_bottom' => 10
    ])->download('custom_config.pdf');
}
```

#### Saving a PDF

[](#saving-a-pdf)

```
public function savePdf()
{
    $html = view('pdf.template', ['title' => 'Report'])->render();
    $path = PdfKh::loadHtml($html)->save('pdfs/report.pdf', 'public');
    return response()->json(['pdf_url' => asset('storage/' . $path)]);
}
```

#### Streaming a PDF

[](#streaming-a-pdf)

```
public function streamPdf()
{
    $html = view('pdf.template', ['title' => 'Live Preview'])->render();
    return PdfKh::loadHtml($html)->stream('live_preview.pdf');
}
```

#### Adding a Text Watermark

[](#adding-a-text-watermark)

```
public function watermarkPdf()
{
    $html = view('pdf.template', ['title' => 'Secret Document'])->render();
    return PdfKh::loadHtml($html)->watermarkText('Confidential', 0.2, 'khmeros', 100, 45, '#FF0000')->download('watermarked.pdf');
}
```

#### Adding an Image Watermark

[](#adding-an-image-watermark)

```
public function watermarkImagePdf()
{
    $html = view('pdf.template', ['title' => 'Image Watermark'])->render();
    return PdfKh::loadHtml($html)->watermarkImage('path/to/image.png', 'p', 'p', 1, false)->download('image_watermarked.pdf');
}
```

#### Adding a Barcode

[](#adding-a-barcode)

```
public function barcodePdf()
{
    $html = view('pdf.template', ['title' => 'Barcode PDF'])->render();
    return PdfKh::loadHtml($html)->writeBarcode('123456789', 10, 10, true, 1, true)->download('barcode.pdf');
}
```

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

[](#configuration)

The `khPdf.php` config file allows you to adjust font paths, default styles, and mPDF options.

Example:

```
'pdf' => [
    'default_font' => 'battambang', // Set your default font here

    // Path to the font files in your public directory
    'font_path' => public_path('fonts/'),

    'font_data' => [
        'battambang' => [ // lowercase letters only in font key
            'R' => 'KhmerOSbattambang.ttf',
            'B' => 'KhmerOSBattambang-Bold.ttf',
            'useOTL' => 0xFF,
        ],
        'khmermuol' => [ // lowercase letters only in font key
            'R' => 'KhmerOSmuol.ttf',
            'useOTL' => 0xFF,
        ],
    ],
],
```

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Contributions
-------------

[](#contributions)

Contributions are welcome! Feel free to submit pull requests or issues on the [GitHub repository](https://github.com/Duch-Nuon/laravel-kh-pdf).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance80

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

Total

4

Last Release

125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/585d4970a743b9819038350b7dc06a321bf16d67aa71d3afb341ddd2efbe0e74?d=identicon)[Duch-Nuon](/maintainers/Duch-Nuon)

---

Top Contributors

[![Duch-Nuon](https://avatars.githubusercontent.com/u/94900806?v=4)](https://github.com/Duch-Nuon "Duch-Nuon (74 commits)")

---

Tags

laravelpdfpackagempdfkhmerlaravel pdf khmerkhmer pdf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/khmer-pdf-laravel-kh-pdf/health.svg)

```
[![Health](https://phpackages.com/badges/khmer-pdf-laravel-kh-pdf/health.svg)](https://phpackages.com/packages/khmer-pdf-laravel-kh-pdf)
```

###  Alternatives

[carlos-meneses/laravel-mpdf

Laravel Mpdf: Using Mpdf in Laravel to generate Pdfs.

4403.1M7](/packages/carlos-meneses-laravel-mpdf)

PHPackages © 2026

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