khmer-pdf / laravel-kh-pdf
A simple Laravel package for supporting Khmer font in PDFs using mPdf.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^8.0
- mpdf/mpdf: ^8.0
This package is auto-updated.
Last update: 2024-11-15 16:07:06 UTC
README
Laravel PDF with Khmer Font Support using mPDF.
Installation
To install the package, run the following command:
composer require khmer-pdf/laravel-kh-pdf
Basic Usage:
<?php use Illuminate\Support\Facades\Route; use KhmerPdf\LaravelKhPdf\Facades\PdfKh; Route::get('/', function () { $view = view('test-font')->render(); $pdf = PdfKh::loadHtml($view)->stream('test.pdf'); return $pdf; });
use Illuminate\Support\Facades\Route; use KhmerPdf\LaravelKhPdf\Facades\PdfKh; Route::get('/', function () { $view = view('test-font')->render(); $pdf = PdfKh::loadHtml($view)->addMPdfConfig(['format' => 'A5',])->stream('test.pdf'); return $pdf; });
Available Method
loadHtml(string $html)
download(string $filename)
stream(string $filename)
save(string $path, string $disk = 'public')
addMPdfConfig(array $config)
For more options config: addMPdfConfig(array $config)
An associative array containing configuration options. For a list of available options, refer to mPDF Configuration Options.
https://mpdf.github.io/reference/mpdf-variables/overview.html
Example
addMPdfConfig(['format' => 'A5-L',]);
Setup & Configuration
This guide will show you how to configure the Khmer fonts in the config/khPdf.php
file for PDF generation using khPdf
. By default, the Khmer fonts KhmerOSBattambang, KhmerOS and KhmerOSMuol are supported.
You can more fonts.
'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, ], ], ],
test-font.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> p{ font-size: 25px; /* font-family: 'battambang'; font-weight: bold; */ font-family: 'khmermuol'; } </style> </head> <body> <p>សួស្តី ពិភពលោក ! Hello World</p> </body> </html>