Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Added new method, view(), for use when debugging #129

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/LaravelPdf/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
*/
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
'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
Expand All @@ -50,7 +52,7 @@ public function __construct($html = '', $config = [])
$this->config['instanceConfigurator']($this->mpdf);
}

$this->mpdf->WriteHTML($html);
$this->mpdf->WriteHTML($this->html);
}

protected function getConfig($key)
Expand Down Expand Up @@ -138,4 +140,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;
}
}