invitation = $invitation; $this->company = $invitation->company; $this->account = $this->company->account; $this->config = (new PdfConfiguration($this))->init(); $this->document_type = $document_type; $this->options = $options; } /** * Resolves the PDF generation type and * attempts to generate a PDF from the HTML * string. * * @return mixed | Exception * */ public function getPdf() { try { $pdf = $this->resolvePdfEngine(); $numbered_pdf = $this->pageNumbering($pdf, $this->company); if ($numbered_pdf) { $pdf = $numbered_pdf; } } catch (\Exception $e) { nlog(print_r($e->getMessage(), 1)); throw new \Exception($e->getMessage(), $e->getCode()); } return $pdf; } /** * Renders the dom document to HTML * * @return string * */ public function getHtml(): string { $html = $this->builder->getCompiledHTML(); if (config('ninja.log_pdf_html')) { info($html); } return $html; } /** * Initialize all the services to build the PDF * * @return self */ public function init(): self { $this->html_variables = $this->config->client ? (new HtmlEngine($this->invitation))->generateLabelsAndValues() : (new VendorHtmlEngine($this->invitation))->generateLabelsAndValues(); $this->designer = (new PdfDesigner($this))->build(); $this->builder = (new PdfBuilder($this))->build(); return $this; } /** * resolvePdfEngine * * @return mixed */ private function resolvePdfEngine(): mixed { if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { $pdf = (new Phantom)->convertHtmlToPdf($this->getHtml()); } elseif (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') { $pdf = (new NinjaPdf())->build($this->getHtml()); } else { $pdf = $this->makePdf(null, null, $this->getHtml()); } return $pdf; } }