Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/PdfReader/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,24 @@ public function getContentStream()
if (!($content instanceof PdfStream)) {
continue;
}
$result[] = $content->getUnfilteredStream();

try {
$result[] = $content->getUnfilteredStream();
} catch (FilterException $e) {
// ignore streams that cannot be unfiltered
}
}

return \implode("\n", $result);
}

if ($contents instanceof PdfStream) {
return $contents->getUnfilteredStream();
try {
return $contents->getUnfilteredStream();
} catch (FilterException $e) {
// ignore streams that cannot be unfiltered
return '';
}
}

throw new PdfReaderException(
Expand Down
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/functional/PdfReader/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,33 @@ public function testGetAttributeWithRecursion()
$this->expectExceptionMessage('Indirect reference recursion detected (4).');
$page->getAttribute('Rotate');
}

public function testGetContentStreamWithFaultyStreamsInContentsArray()
{
$stream = StreamReader::createByFile(__DIR__ . '/../../_files/pdfs/specials/invalid_zlib_streams_issue252.pdf');
$parser = new PdfParser($stream);

$pdfReader = new PdfReader($parser);
$page = $pdfReader->getPage(1);
$content = $page->getContentStream();
$this->assertStringStartsWith(
"q\n"
. "2.8346457 0 0 2.8346457 0 0 cm q\n"
. "BT\n"
. "0 0 0 1 k\n"
. "/F0 6 Tf\n"
. "18.6606 277.3104 Td\n",
$content
);

$this->assertStringEndsWith(
"(Moms 25% 2793,75 \(11175,00\) ) Tj\n"
. "ET\n"
. "Q\n"
. "Q",
$content
);

$this->assertSame(8520, \strlen($content));
}
}