From 2d27efab66d948266dd439db5caeeb8ed1756b4c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 16 Aug 2023 20:23:41 +1000 Subject: [PATCH] Add string output as option --- src/ZugferdDocumentPdfBuilder.php | 11 +++++++++++ tests/testcases/PdfBuilderEn16931Test.php | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/ZugferdDocumentPdfBuilder.php b/src/ZugferdDocumentPdfBuilder.php index 2f1945d2..67214b79 100644 --- a/src/ZugferdDocumentPdfBuilder.php +++ b/src/ZugferdDocumentPdfBuilder.php @@ -91,6 +91,17 @@ public function saveDocument(string $toFilename): ZugferdDocumentPdfBuilder return $this; } + + /** + * Returns the PDF as a string + * + * @param string $toFilename + * @return string + */ + public function downloadString(string $toFilename): string + { + return $this->pdfWriter->Output($toFilename, 'S'); + } /** * Internal function which sets up the PDF diff --git a/tests/testcases/PdfBuilderEn16931Test.php b/tests/testcases/PdfBuilderEn16931Test.php index e83e6267..bd4ef6bd 100644 --- a/tests/testcases/PdfBuilderEn16931Test.php +++ b/tests/testcases/PdfBuilderEn16931Test.php @@ -91,6 +91,15 @@ public function testBuildPdf(): void $this->assertTrue(file_exists(self::$destPdfFilename)); } + public function testBuildPdfString(): void + { + $pdfBuilder = new ZugferdDocumentPdfBuilder(self::$document, self::$sourcePdfFilename); + $pdfBuilder->generateDocument(); + $pdfBuilder->downloadString(self::$destPdfFilename); + + $this->assertIsString(self::$destPdfFilename); + } + public function testPdfMetaData(): void { $pdfParser = new PdfParser();