From bf134fa6de7411f5754c057ea141c5223c6665e6 Mon Sep 17 00:00:00 2001 From: Trent Steel Date: Mon, 3 Nov 2014 11:01:42 +1000 Subject: [PATCH] Always return options to default hasHtmlHeader and hasHtmlFooter must return to their default state each time handleOptions() is called. Otherwise, if you generate 2 pdf files within 1 request (1 with a footer and 1 without it will throw an error). Consider the following: ```php $snappyPdf->generateFromHtml($pdf1Html, $pdf1File, array( 'page-size' => 'A5', 'margin-right' => 0, 'margin-left' => 0, 'footer-html' => $footer ), true); $snappyPdf->generateFromHtml($pdf2Html, $pdf2File, array( 'page-size' => 'A5', 'margin-right' => 0, 'margin-left' => 0 ), true); ``` When the second pdf is generated the following error is generated: ```Notice: Undefined index: footer-html in /usr/local/zend/apache2/htdocs/lighting-illusions/v3/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php line 66``` This is because the first file generated is changing the protected $hasHtmlFooter value to true but there is no footer available. --- src/Knp/Snappy/Pdf.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Knp/Snappy/Pdf.php b/src/Knp/Snappy/Pdf.php index be2ee771..788b20b3 100644 --- a/src/Knp/Snappy/Pdf.php +++ b/src/Knp/Snappy/Pdf.php @@ -29,6 +29,9 @@ public function __construct($binary = null, array $options = array()) */ protected function handleOptions(array $options = array()) { + $this->hasHtmlHeader = false; + $this->hasHtmlFooter = false; + $headerHtml = isset($options['header-html']) ? $options['header-html'] : null; if (null !== $headerHtml && !filter_var($headerHtml, FILTER_VALIDATE_URL) && !$this->isFile($headerHtml)) { $options['header-html'] = $this->createTemporaryFile($headerHtml, 'html');