1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 09:04:35 +01:00
invoiceninja/app/Utils/Traits/Pdf/PdfMaker.php

48 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2020-12-21 16:32:04 +01:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Utils\Traits\Pdf;
2021-04-12 06:36:51 +02:00
use App\Exceptions\InternalPDFFailure;
2020-12-21 16:32:04 +01:00
use Beganovich\Snappdf\Snappdf;
trait PdfMaker
{
/**
* Returns a PDF stream.
*
* @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
*/
public function makePdf($header, $footer, $html)
{
2020-12-21 16:32:04 +01:00
$pdf = new Snappdf();
2020-07-01 00:29:05 +02:00
if (config('ninja.snappdf_chromium_path')) {
$pdf->setChromiumPath(config('ninja.snappdf_chromium_path'));
}
2021-04-12 06:36:51 +02:00
$generated = $pdf
->setHtml($html)
->generate();
if($generated)
return $generated;
throw new InternalPDFFailure('There was an issue generating the PDF locally');
2020-07-01 00:29:05 +02:00
}
}