2020-02-19 21:44:12 +01:00
|
|
|
<?php
|
2020-03-18 10:40:15 +01:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-03-18 10:40:15 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-02-19 21:44:12 +01:00
|
|
|
|
|
|
|
namespace App\Utils\Traits\Pdf;
|
|
|
|
|
2020-12-20 08:02:58 +01:00
|
|
|
use Beganovich\ChromiumPdf\ChromiumPdf;
|
2020-02-19 21:44:12 +01:00
|
|
|
use Spatie\Browsershot\Browsershot;
|
|
|
|
|
|
|
|
trait PdfMaker
|
|
|
|
{
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Returns a PDF stream.
|
2020-02-19 21:44:12 +01:00
|
|
|
*
|
|
|
|
* @param string $header Header to be included in PDF
|
|
|
|
* @param string $footer Footer to be included in PDF
|
|
|
|
* @param string $html The HTML object to be converted into PDF
|
|
|
|
*
|
|
|
|
* @return string The PDF string
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public function makePdf($header, $footer, $html)
|
|
|
|
{
|
2020-12-14 17:23:04 +01:00
|
|
|
if (config('ninja.experimental_pdf_engine')) {
|
|
|
|
$pdf = new ChromiumPdf();
|
|
|
|
|
|
|
|
return $pdf
|
|
|
|
->setChromiumPath(config('ninja.experimental_pdf_engine_chromium_path'))
|
|
|
|
->setHtml($html)
|
|
|
|
->generate();
|
|
|
|
}
|
|
|
|
|
2020-07-01 00:29:05 +02:00
|
|
|
$browser = Browsershot::html($html);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (config('ninja.system.node_path')) {
|
2020-07-01 00:29:05 +02:00
|
|
|
$browser->setNodeBinary(config('ninja.system.node_path'));
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-07-01 00:29:05 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (config('ninja.system.npm_path')) {
|
2020-07-01 00:29:05 +02:00
|
|
|
$browser->setNpmBinary(config('ninja.system.npm_path'));
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-07-01 00:29:05 +02:00
|
|
|
|
|
|
|
return $browser->deviceScaleFactor(1)
|
|
|
|
->showBackground()
|
|
|
|
->deviceScaleFactor(1)
|
|
|
|
->waitUntilNetworkIdle(true)
|
2020-09-06 04:23:04 +02:00
|
|
|
->noSandbox()
|
2020-12-21 00:11:33 +01:00
|
|
|
->ignoreHttpsErrors()
|
2020-07-01 00:29:05 +02:00
|
|
|
->pdf();
|
|
|
|
}
|
|
|
|
}
|