Skip to content

Commit 57a3a2e

Browse files
committed
Merge branch 'release/4.0.1'
2 parents e560041 + be20b36 commit 57a3a2e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vianetz Pdf Library
1+
# vianetz PDF Library
22

33
This library offers an easy-to-use API for PDF generation and merging.
44
Internally it uses the DomPDF library for PDF generation and TCPDF for merging.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vianetz/pdf-generator",
3-
"description": "The vianetz PDF library that generates PDF documents.",
3+
"description": "A library that supports method for generating PDF documents based on DomPdf and FPDI.",
44
"type": "library",
55
"keywords": [
66
"vianetz",

src/Model/Generator/Dompdf.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,27 @@ private function getDompdfOptions(): array
8787
];
8888
}
8989

90+
/** @see https://github.com/dompdf/dompdf/issues/1636#issuecomment-490372233 */
9091
private function injectPageCount(): void
9192
{
93+
/** @var \Dompdf\Adapter\CPDF $canvas */
9294
$canvas = $this->domPdf->getCanvas();
93-
$pdf = $canvas->get_cpdf(); // @phpstan-ignore-line
95+
96+
$search = [self::TOTAL_PAGE_COUNT_PLACEHOLDER, self::insertNullByteBeforeEachCharacter(self::TOTAL_PAGE_COUNT_PLACEHOLDER)];
97+
$replace = [(string)$canvas->get_page_count(), self::insertNullByteBeforeEachCharacter((string)$canvas->get_page_count())];
98+
99+
$pdf = $canvas->get_cpdf();
94100

95101
foreach ($pdf->objects as &$o) {
96102
if ($o['t'] === 'contents') {
97-
$o['c'] = str_replace(self::TOTAL_PAGE_COUNT_PLACEHOLDER, (string)$canvas->get_page_count(), $o['c']);
103+
$o['c'] = str_replace($search, $replace, $o['c']);
98104
}
99105
}
100106
}
107+
108+
/** @see https://gist.github.com/enumag/f670865b70d11e0b8156b1e92acc3c92 */
109+
private static function insertNullByteBeforeEachCharacter(string $string): string
110+
{
111+
return "\u{0000}" . substr(chunk_split($string, 1, "\u{0000}"), 0, -1);
112+
}
101113
}

0 commit comments

Comments
 (0)