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;
|
|
|
|
|
|
|
|
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-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-07-01 00:29:05 +02:00
|
|
|
->pdf();
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 08:14:57 +01:00
|
|
|
|
|
|
|
// if($header && $footer){
|
|
|
|
// $browser = Browsershot::html($html)
|
2020-03-21 06:37:30 +01:00
|
|
|
// ->headerHtml($header)
|
|
|
|
// ->footerHtml($footer);
|
2020-03-05 08:14:57 +01:00
|
|
|
// }
|
|
|
|
// elseif($header){
|
|
|
|
// $browser = Browsershot::html($html)
|
2020-03-21 06:37:30 +01:00
|
|
|
// ->headerHtml($header);
|
2020-03-05 08:14:57 +01:00
|
|
|
// }
|
|
|
|
// else if($footer){
|
|
|
|
// $browser = Browsershot::html($html)
|
2020-03-21 06:37:30 +01:00
|
|
|
// ->footerHtml($footer);
|
2020-03-05 08:14:57 +01:00
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// $browser = Browsershot::html($html);
|
|
|
|
// }
|
2020-09-06 11:38:10 +02:00
|
|
|
//
|
|
|
|
//
|
2020-07-01 00:29:05 +02:00
|
|
|
// // return Browsershot::html($html)
|
2020-03-05 08:14:57 +01:00
|
|
|
// //->showBrowserHeaderAndFooter()
|
|
|
|
// //->headerHtml($header)
|
|
|
|
// //->footerHtml($footer)
|
|
|
|
// ->deviceScaleFactor(1)
|
|
|
|
// ->showBackground()
|
|
|
|
// ->waitUntilNetworkIdle(true) ->pdf();
|
|
|
|
// //->margins(10,10,10,10)
|
|
|
|
// //->savePdf('test.pdf');
|
2020-09-06 11:38:10 +02:00
|
|
|
//
|
2020-07-01 00:29:05 +02:00
|
|
|
// $browser->format('A4');
|
2020-09-06 11:38:10 +02:00
|
|
|
// $browser->landscape();
|