From e6ae53e5652d27b21e28388d18ba3e843428cb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Fri, 22 Jul 2022 11:05:53 +0200 Subject: [PATCH 1/2] Define font via env var --- README.md | 7 +++++++ src/FpdfServiceProvider.php | 6 +++++- src/config/fpdf.php | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2761a37..037bc53 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ Route::get('/', function (Codedge\Fpdf\Fpdf\Fpdf $fpdf) { }); ``` +### Defining fonts + +FPDF comes with a set of fonts already defined and stored in the `src/Fpdf/font` directory. +If you want to add your own font, please have a look at the [Adding new fonts and encodings](http://www.fpdf.org/en/tutorial/tuto7.htm) tutorial. + +You can change the font path, by using the `FPDF_FONTPATH` environment variable. + ## Use in Laravel Vapor If you want to use [Laravel Vapor](https://vapor.laravel.com) to host your application, diff --git a/src/FpdfServiceProvider.php b/src/FpdfServiceProvider.php index afb4d2b..432bc43 100644 --- a/src/FpdfServiceProvider.php +++ b/src/FpdfServiceProvider.php @@ -43,6 +43,10 @@ public function register() */ public function registerFpdf() { + if(config('fpdf.font_path') !== null) { + define('FPDF_FONTPATH', config('fpdf.font_path')); + } + $this->app->singleton('fpdf', function() { return new Fpdf\Fpdf( @@ -60,4 +64,4 @@ public function provides() { return ['fpdf']; } -} \ No newline at end of file +} diff --git a/src/config/fpdf.php b/src/config/fpdf.php index de440b4..c19042b 100644 --- a/src/config/fpdf.php +++ b/src/config/fpdf.php @@ -14,6 +14,7 @@ 'orientation' => 'P', 'unit' => 'mm', 'size' => 'A4', + 'font_path' => env('FPDF_FONTPATH'), /* |-------------------------------------------------------------------------- From 463eb8b0b6193f6b3940026dfdc2bd0f69b25cba Mon Sep 17 00:00:00 2001 From: codedge Date: Fri, 22 Jul 2022 09:06:17 +0000 Subject: [PATCH 2/2] Prettified Code! --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 037bc53..68d4c11 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Route::get('/', function (Codedge\Fpdf\Fpdf\Fpdf $fpdf) { ### Defining fonts FPDF comes with a set of fonts already defined and stored in the `src/Fpdf/font` directory. -If you want to add your own font, please have a look at the [Adding new fonts and encodings](http://www.fpdf.org/en/tutorial/tuto7.htm) tutorial. +If you want to add your own font, please have a look at the [Adding new fonts and encodings](http://www.fpdf.org/en/tutorial/tuto7.htm) tutorial. You can change the font path, by using the `FPDF_FONTPATH` environment variable.