From edbb9c46d2e40784f6524cfd624230f6c0ff0cb7 Mon Sep 17 00:00:00 2001 From: JustCarty Date: Wed, 13 Feb 2019 15:34:32 +0000 Subject: [PATCH 1/2] Added new method, view(), for use when debugging I have added in a new method that can be called in the same way that `stream` is in order to print raw HTML to the browser. This is useful for debugging the HTML to view what the code will look like - roughly. Also, I have modified the comments on the config array so that they reflect the wording from the Mpdf documentation. --- src/LaravelPdf/Pdf.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/LaravelPdf/Pdf.php b/src/LaravelPdf/Pdf.php index 8c88b30..63c7585 100644 --- a/src/LaravelPdf/Pdf.php +++ b/src/LaravelPdf/Pdf.php @@ -13,22 +13,26 @@ */ class Pdf { + protected $html = ''; protected $config = []; public function __construct($html = '', $config = []) { + $this->html = $html; $this->config = $config; $mpdf_config = [ - 'mode' => $this->getConfig('mode'), // mode - default '' - 'format' => $this->getConfig('format'), // format - A4, for example, default '' - 'margin_left' => $this->getConfig('margin_left'), // margin_left - 'margin_right' => $this->getConfig('margin_right'), // margin right - 'margin_top' => $this->getConfig('margin_top'), // margin top - 'margin_bottom' => $this->getConfig('margin_bottom'), // margin bottom - 'margin_header' => $this->getConfig('margin_header'), // margin header - 'margin_footer' => $this->getConfig('margin_footer'), // margin footer - 'tempDir' => $this->getConfig('tempDir') // margin footer + 'mode' => $this->getConfig('mode'), // Mode of the document. + 'format' => $this->getConfig('format'), // Can be specified either as a pre-defined page size, or as an array of width and height in millimetres + 'default_font_size' => $this->getConfig('default_font_size'), // Sets the default document font size in points (pt). + 'default_font' => $this->getConfig('default_font'), // Sets the default font-family for the new document. + 'margin_left' => $this->getConfig('margin_left'), // Set the page margins for the new document. + 'margin_right' => $this->getConfig('margin_right'), // Set the page margins for the new document. + 'margin_top' => $this->getConfig('margin_top'), // Set the page margins for the new document. + 'margin_bottom' => $this->getConfig('margin_bottom'), // Set the page margins for the new document. + 'margin_header' => $this->getConfig('margin_header'), // Set the page margins for the new document. + 'margin_footer' => $this->getConfig('margin_footer'), // Set the page margins for the new document. + 'tempDir' => $this->getConfig('tempDir') // temporary directory ]; // Handle custom fonts @@ -50,7 +54,7 @@ public function __construct($html = '', $config = []) $this->config['instanceConfigurator']($this->mpdf); } - $this->mpdf->WriteHTML($html); + $this->mpdf->WriteHTML($this->html); } protected function getConfig($key) @@ -138,4 +142,15 @@ public function stream($filename = 'document.pdf') { return $this->mpdf->Output($filename, 'I'); } + + /** + * Return the rendered view as an HTML string to show in the browser. + * Useful for debugging the HTML code to see what it looks like. + * + * @return string + */ + public function view() + { + return $this->html; + } } From 4410a25bf289424077769e5a0420f668ae0a2572 Mon Sep 17 00:00:00 2001 From: JustCarty Date: Wed, 13 Feb 2019 15:38:45 +0000 Subject: [PATCH 2/2] Update Pdf.php --- src/LaravelPdf/Pdf.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/LaravelPdf/Pdf.php b/src/LaravelPdf/Pdf.php index 63c7585..1d76688 100644 --- a/src/LaravelPdf/Pdf.php +++ b/src/LaravelPdf/Pdf.php @@ -24,8 +24,6 @@ public function __construct($html = '', $config = []) $mpdf_config = [ 'mode' => $this->getConfig('mode'), // Mode of the document. 'format' => $this->getConfig('format'), // Can be specified either as a pre-defined page size, or as an array of width and height in millimetres - 'default_font_size' => $this->getConfig('default_font_size'), // Sets the default document font size in points (pt). - 'default_font' => $this->getConfig('default_font'), // Sets the default font-family for the new document. 'margin_left' => $this->getConfig('margin_left'), // Set the page margins for the new document. 'margin_right' => $this->getConfig('margin_right'), // Set the page margins for the new document. 'margin_top' => $this->getConfig('margin_top'), // Set the page margins for the new document.