From 670207071d9258905ebf8a3877558459f9d6d6bb Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 12 Feb 2024 15:00:50 +0100 Subject: [PATCH 1/4] fix chromium to close page instead of closing browser Co-authored-by: Vincent Robert --- src/Processor/Chromium.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processor/Chromium.php b/src/Processor/Chromium.php index dafc77c..4d1b25a 100644 --- a/src/Processor/Chromium.php +++ b/src/Processor/Chromium.php @@ -136,7 +136,7 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF Logger::debug('Could not create pdf with chromium: '. print_r($e, true)); $output = (string) $e; } finally { - $browser->close(); + $page->close(); } return $output; From ca988bc0b586d38fa03e63b8c77e5857bbde94d4 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 12 Feb 2024 15:03:49 +0100 Subject: [PATCH 2/4] Update Chromium.php --- src/Processor/Chromium.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Processor/Chromium.php b/src/Processor/Chromium.php index 4d1b25a..970bb58 100644 --- a/src/Processor/Chromium.php +++ b/src/Processor/Chromium.php @@ -132,11 +132,10 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } else { $output = base64_decode($pdf->getBase64()); } + $page->close(); } catch (\Throwable $e) { Logger::debug('Could not create pdf with chromium: '. print_r($e, true)); - $output = (string) $e; - } finally { - $page->close(); + $output = (string) $e; } return $output; From 6e8bc6571c70e29eed8bdc783745665bef7a4aa8 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 12 Feb 2024 15:05:28 +0100 Subject: [PATCH 3/4] Update Chromium.php --- src/Processor/Chromium.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Processor/Chromium.php b/src/Processor/Chromium.php index 970bb58..5fd6254 100644 --- a/src/Processor/Chromium.php +++ b/src/Processor/Chromium.php @@ -120,8 +120,8 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF ]); } + $page = $browser->createPage(); try { - $page = $browser->createPage(); $page->setHtml($html, 5000); $pdf = $page->pdf($params); @@ -132,10 +132,11 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } else { $output = base64_decode($pdf->getBase64()); } - $page->close(); } catch (\Throwable $e) { Logger::debug('Could not create pdf with chromium: '. print_r($e, true)); $output = (string) $e; + } finally { + $page->close(); } return $output; From e6fa48eca3ae59651c8c19daa9b726fe2d4658d4 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 12 Feb 2024 15:06:41 +0100 Subject: [PATCH 4/4] remove empty spaces --- src/Processor/Chromium.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Processor/Chromium.php b/src/Processor/Chromium.php index 5fd6254..6c074f3 100644 --- a/src/Processor/Chromium.php +++ b/src/Processor/Chromium.php @@ -134,8 +134,8 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF } } catch (\Throwable $e) { Logger::debug('Could not create pdf with chromium: '. print_r($e, true)); - $output = (string) $e; - } finally { + $output = (string) $e; + } finally { $page->close(); }