Add support for custom Chromium path (ie. support for Windows & Mac)

This commit is contained in:
Benjamin Beganović 2020-12-25 14:15:57 +01:00
parent 2963824924
commit 9f58ccb028
4 changed files with 20 additions and 5 deletions

View File

@ -221,9 +221,13 @@ class SetupController extends Controller
return $this->testPhantom(); return $this->testPhantom();
} }
$snappdf = new Snappdf(); $pdf = new Snappdf();
$pdf = $snappdf if (config('ninja.snappdf_chromium_path')) {
$pdf->setChromiumPath(config('ninja.snappdf_chromium_path'));
}
$pdf = $pdf
->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!') ->setHtml('GENERATING PDFs WORKS! Thank you for using Invoice Ninja!')
->generate(); ->generate();

View File

@ -29,6 +29,10 @@ trait PdfMaker
{ {
$pdf = new Snappdf(); $pdf = new Snappdf();
if (config('ninja.snappdf_chromium_path')) {
$pdf->setChromiumPath(config('ninja.snappdf_chromium_path'));
}
return $pdf return $pdf
->setHtml($html) ->setHtml($html)
->generate(); ->generate();

View File

@ -137,4 +137,5 @@ return [
], ],
'log_pdf_html' => env('LOG_PDF_HTML', false), 'log_pdf_html' => env('LOG_PDF_HTML', false),
'expanded_logging' => env('EXPANDED_LOGGING', false), 'expanded_logging' => env('EXPANDED_LOGGING', false),
'snappdf_chromium_path' => env('SNAPPDF_CHROMIUM_PATH', false),
]; ];

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Invoice Ninja (https://invoiceninja.com). * Invoice Ninja (https://invoiceninja.com).
* *
@ -8,6 +9,7 @@
* *
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace Tests\Pdf; namespace Tests\Pdf;
use Beganovich\Snappdf\Snappdf; use Beganovich\Snappdf\Snappdf;
@ -19,16 +21,20 @@ use Tests\TestCase;
*/ */
class PdfGenerationTest extends TestCase class PdfGenerationTest extends TestCase
{ {
public function setUp() :void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
} }
public function testPdfGeneration() public function testPdfGeneration()
{ {
$snappdf = new Snappdf(); $pdf = new Snappdf();
$pdf = $snappdf if (config('ninja.snappdf_chromium_path')) {
$pdf->setChromiumPath(config('ninja.snappdf_chromium_path'));
}
$pdf = $pdf
->setHtml('<h1>Invoice Ninja</h1>') ->setHtml('<h1>Invoice Ninja</h1>')
->generate(); ->generate();