Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround for the Issue #450 #453

Merged
merged 8 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
Binary file added samples/bugs/Issue450.pdf
Binary file not shown.
11 changes: 7 additions & 4 deletions src/Smalot/PdfParser/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public function getTextArray(self $page = null): array

$header = new Header([], $this->document);
$contents = new PDFObject($this->document, $header, $new_content, $this->config);
} else {
try {
$contents->getTextArray($this);
} catch (\Error $e) {
k00ni marked this conversation as resolved.
Show resolved Hide resolved
return $contents->getTextArray();
}
}
} elseif ($contents instanceof ElementArray) {
// Create a virtual global content.
Expand Down Expand Up @@ -343,10 +349,7 @@ public function extractDecodedRawData(array $extractedRawData = null): array
}
$tmpText = $data[$i]['c'];
$decodedText = '';
izabala marked this conversation as resolved.
Show resolved Hide resolved
if (isset($currentFont)) {
$decodedText = $currentFont->decodeOctal($tmpText);
//$tmpText = $currentFont->decodeHexadecimal($tmpText, false);
}
$decodedText = isset($currentFont) ? $currentFont->decodeOctal($tmpText) : $tmpText;
$decodedText = str_replace(
['\\\\', '\(', '\)', '\n', '\r', '\t', '\ '],
['\\', '(', ')', "\n", "\r", "\t", ' '],
Expand Down
41 changes: 41 additions & 0 deletions tests/Integration/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,45 @@ public function testGetTextXY()
$result = $page->getTextXY(174, 827, 1, 1);
$this->assertStringContainsString('Purchase 2', $result[0][1]);
}

public function testExtractDecodedRawDataIssue450()
{
$filename = $this->rootDir.'/samples/bugs/Issue450.pdf';
$parser = $this->getParserInstance();
$document = $parser->parseFile($filename);
$pages = $document->getPages();
$page = $pages[0];
$extractedDecodedRawData = $page->extractDecodedRawData();
$this->assertIsArray($extractedDecodedRawData);
$this->assertGreaterThan(3, \count($extractedDecodedRawData));
$this->assertIsArray($extractedDecodedRawData[3]);
$this->assertEquals('TJ', $extractedDecodedRawData[3]['o']);
$this->assertIsArray($extractedDecodedRawData[3]['c']);
$this->assertIsArray($extractedDecodedRawData[3]['c'][0]);
$this->assertEquals(3, \count($extractedDecodedRawData[3]['c'][0]));
$this->assertEquals('{signature:signer505906:Please+Sign+Here}', $extractedDecodedRawData[3]['c'][0]['c']);
}

public function testGetDataTmIssue450()
{
$filename = $this->rootDir.'/samples/bugs/Issue450.pdf';
$parser = $this->getParserInstance();
$document = $parser->parseFile($filename);
$pages = $document->getPages();
$page = $pages[0];
$dataTm = $page->getDataTm();
$this->assertIsArray($dataTm);
$this->assertEquals(1, \count($dataTm));
$this->assertIsArray($dataTm[0]);
$this->assertEquals(2, \count($dataTm[0]));
$this->assertIsArray($dataTm[0][0]);
$this->assertEquals(6, \count($dataTm[0][0]));
$this->assertEquals(1, $dataTm[0][0][0]);
$this->assertEquals(0, $dataTm[0][0][1]);
$this->assertEquals(0, $dataTm[0][0][2]);
$this->assertEquals(1, $dataTm[0][0][3]);
$this->assertEquals(67.5, $dataTm[0][0][4]);
$this->assertEquals(756.25, $dataTm[0][0][5]);
$this->assertEquals('{signature:signer505906:Please+Sign+Here}', $dataTm[0][1]);
}
}
6 changes: 3 additions & 3 deletions tests/Integration/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function testRetainImageContentImpact()
}

$filename = $this->rootDir.'/samples/bugs/Issue104a.pdf';
$iterations = 1;
$iterations = 2;

/*
* check default (= true)
Expand All @@ -335,7 +335,7 @@ public function testRetainImageContentImpact()
}

$usedMemory = memory_get_usage(true);
$this->assertTrue($usedMemory > 100000000, 'Memory is only '.$usedMemory);
$this->assertTrue($usedMemory > 200000000, 'Memory is only '.$usedMemory);
$this->assertTrue(null != $document && 0 < \strlen($document->getText()));

// force garbage collection
Expand All @@ -359,7 +359,7 @@ public function testRetainImageContentImpact()
* note: the following memory value is set manually and may differ from system to system.
* it must be high enough to not produce a false negative though.
*/
$this->assertTrue($usedMemory < 106000000, 'Memory is '.$usedMemory);
$this->assertTrue($usedMemory < 107000000, 'Memory is '.$usedMemory);
$this->assertTrue(0 < \strlen($document->getText()));
}
}
Expand Down