Skip to content

Commit

Permalink
Added flags and logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
mralston committed Oct 20, 2023
1 parent 75bb24c commit 6e62e10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.DS_Store
~*
~*
vendor
composer.lock
25 changes: 22 additions & 3 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Pdf
private const SOURCE_HTML = 3;
private const SOURCE_VIEW = 4;

private $logger = null;
private $customFlags = [];

public function __construct()
{
$this->setSecurityToken(config('pdf.security_token'));
Expand Down Expand Up @@ -76,6 +79,20 @@ public static function fromView(?string $view = null, ?array $data = []): self
->loadView($view, $data);
}

public function withLogger($logger = null)
{
$this->logger = $logger ?? Log::getLogger();

return $this;
}

public function withFlags(array $flags = [])
{
$this->customFlags = $flags;

return $this;
}

public function loadFile(?string $file = null): self
{
$this->file = $file;
Expand Down Expand Up @@ -205,6 +222,8 @@ private function renderUrl(?string $url = null): self
'noSandbox' => true,
'ignoreCertificateErrors' => true,
'headers' => $this->prepareRequestHeaders(),
'debugLogger' => $this->logger,
'customFlags' => $this->customFlags,
]);

$page = $this->browser->createPage();
Expand Down Expand Up @@ -255,7 +274,7 @@ public function output(): string

$base64 = $this->pdf
->getResponseReader()
->waitForResponse(5000)
->waitForResponse($this->timeout * 1000)
->getResultData('data');

$this->browser->close();
Expand All @@ -272,7 +291,7 @@ public function stream(): Response

$base64 = $this->pdf
->getResponseReader()
->waitForResponse(5000)
->waitForResponse($this->timeout * 1000)
->getResultData('data');

$this->browser->close();
Expand All @@ -291,7 +310,7 @@ public function download(?string $filename = 'document.pdf'): Response

$base64 = $this->pdf
->getResponseReader()
->waitForResponse(5000)
->waitForResponse($this->timeout * 1000)
->getResultData('data');

$this->browser->close();
Expand Down

0 comments on commit 6e62e10

Please sign in to comment.