diff --git a/src/Modules/Document.php b/src/Modules/Document.php index 861662c..8a8f958 100644 --- a/src/Modules/Document.php +++ b/src/Modules/Document.php @@ -13,6 +13,7 @@ use setasign\SetaFpdf\Position\Converter; use setasign\SetaFpdf\SetaFpdf; use setasign\SetaFpdf\StateBuffer\StateBufferInterface; +use setasign\SetaPDF2\Core\Font\TrueType\Subset; class Document implements StateBufferInterface { @@ -489,6 +490,12 @@ public function output($destination, $name, ?array $displayMode = null) \call_user_func($this->footerCallable); $this->pageBreakDisabled = false; + foreach ($this->manager->getFont()->getUsedFonts() as $font) { + if ($font instanceof Subset) { + $font->createSubset(); + } + } + self::applyDisplayMode($this->document, $displayMode); $info = $this->document->getInfo(); $info->setProducer('SetaFPDF ' . SetaFpdf::VERSION); diff --git a/src/SetaFpdf.php b/src/SetaFpdf.php index 7d71128..478bda9 100644 --- a/src/SetaFpdf.php +++ b/src/SetaFpdf.php @@ -460,12 +460,6 @@ public function Output($dest = '', $name = '') $name = 'doc.pdf'; } - foreach ($this->manager->getFont()->getUsedFonts() as $font) { - if ($font instanceof Subset) { - $font->createSubset(); - } - } - return $this->manager->getDocument()->output($dest, $name, $this->displayMode); } diff --git a/tests/visual/SetaFpdf/Special/FooterTest.php b/tests/visual/SetaFpdf/Special/FooterTest.php index 13f717d..56fc502 100644 --- a/tests/visual/SetaFpdf/Special/FooterTest.php +++ b/tests/visual/SetaFpdf/Special/FooterTest.php @@ -2,6 +2,7 @@ namespace setasign\tests\visual\SetaFpdf\Special; +use setasign\SetaFpdf\SetaFpdf; use setasign\tests\TestProxy; use setasign\tests\visual\SetaFpdf\Special\Footer\FPDFCustom; use setasign\tests\visual\SetaFpdf\Special\Footer\SetaFpdfCustom; @@ -38,4 +39,28 @@ public function testSpecialFooter() $this->assertProxySame($proxy, 0.4, self::DPI); } + + public function testFooterWithCustomFont() + { + $setaFpdf = new class extends SetaFpdf { + public function Footer() + { + $this->SetY(-15); + $this->Cell(0, 10, 'This is a footer'); + } + }; + + $setaFpdf->AddPage(); + $setaFpdf->AddFont('DejaVuSans','', __DIR__ . '/../../../../assets/fonts/DejaVu/DejaVuSans.ttf'); + $setaFpdf->SetFont('DejaVuSans', '', 12); + $setaFpdf->Cell(0, 10, 'Hello World'); + + $testFile = __DIR__ . '/FooterWithCustomFontActualResult.pdf'; + $setaFpdf->Output('F', $testFile); + $this->assertPdfsEqual([ + __DIR__ . '/FooterWithCustomFontExpectedResult.pdf', + $testFile + ], self::DPI, 1, false); + \unlink($testFile); + } } \ No newline at end of file diff --git a/tests/visual/SetaFpdf/Special/FooterWithCustomFontExpectedResult.pdf b/tests/visual/SetaFpdf/Special/FooterWithCustomFontExpectedResult.pdf new file mode 100644 index 0000000..a43e57c Binary files /dev/null and b/tests/visual/SetaFpdf/Special/FooterWithCustomFontExpectedResult.pdf differ