1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file This file is part of the PdfParser library. |
5
|
|
|
* |
6
|
|
|
* @author Konrad Abicht <[email protected]> |
7
|
|
|
* @date 2020-06-01 |
8
|
|
|
* |
9
|
|
|
* @author Sébastien MALOT <[email protected]> |
10
|
|
|
* @date 2017-01-03 |
11
|
|
|
* |
12
|
|
|
* @license LGPLv3 |
13
|
|
|
* @url <https://github.com/smalot/pdfparser> |
14
|
|
|
* |
15
|
|
|
* PdfParser is a pdf library written in PHP, extraction oriented. |
16
|
|
|
* Copyright (C) 2017 - Sébastien MALOT <[email protected]> |
17
|
|
|
* |
18
|
|
|
* This program is free software: you can redistribute it and/or modify |
19
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
20
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
21
|
|
|
* (at your option) any later version. |
22
|
|
|
* |
23
|
|
|
* This program is distributed in the hope that it will be useful, |
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26
|
|
|
* GNU Lesser General Public License for more details. |
27
|
|
|
* |
28
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
29
|
|
|
* along with this program. |
30
|
|
|
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
namespace Tests\Smalot\PdfParser\Integration\RawData; |
34
|
|
|
|
35
|
|
|
use Smalot\PdfParser\Config; |
36
|
|
|
use Smalot\PdfParser\RawData\RawDataParser; |
37
|
|
|
use Tests\Smalot\PdfParser\TestCase; |
38
|
|
|
|
39
|
|
|
class RawDataParserHelper extends RawDataParser |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* Expose protected function "getRawObject". |
43
|
|
|
*/ |
44
|
|
|
public function exposeGetRawObject($pdfData, $offset = 0) |
45
|
|
|
{ |
46
|
|
|
return $this->getRawObject($pdfData, $offset); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
class RawDataParserTest extends TestCase |
51
|
|
|
{ |
52
|
|
|
protected function setUp(): void |
53
|
|
|
{ |
54
|
|
|
parent::setUp(); |
55
|
|
|
|
56
|
|
|
$this->fixture = new RawDataParserHelper([], new Config()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Tests buggy behavior of getRawObject. |
61
|
|
|
* |
62
|
|
|
* When PDF has corrupted xref table getRawObject may run into an infinite loop. |
63
|
|
|
* |
64
|
|
|
* @see https://github.com/smalot/pdfparser/issues/372 |
65
|
|
|
* @see https://github.com/smalot/pdfparser/pull/377 |
66
|
|
|
*/ |
67
|
|
|
public function testGetRawObjectIssue372() |
68
|
|
|
{ |
69
|
|
|
// The following $data content is a minimal example to trigger the infinite loop |
70
|
|
|
$data = '<</Producer (eDkºãa˜þõ‚LÅòÕ�PïÙ��)©)>>'; |
71
|
|
|
|
72
|
|
|
// calling "getRawObject" via "exposeGetRawObject" would result in an infinite loop |
73
|
|
|
// if the fix is not there. |
74
|
|
|
$result = $this->fixture->exposeGetRawObject($data); |
75
|
|
|
|
76
|
|
|
$this->assertEquals( |
77
|
|
|
[ |
78
|
|
|
'<<', |
79
|
|
|
[ |
80
|
|
|
['/', 'Producer', 11], |
81
|
|
|
['(', 'eDkºãa˜þõ‚LÅòÕ�PïÙ��', 52], |
82
|
|
|
], |
83
|
|
|
52, |
84
|
|
|
], |
85
|
|
|
$result |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Tests buggy behavior of decodeXrefStream. |
91
|
|
|
* |
92
|
|
|
* @see https://github.com/smalot/pdfparser/issues/30 |
93
|
|
|
* @see https://github.com/smalot/pdfparser/issues/192 |
94
|
|
|
* @see https://github.com/smalot/pdfparser/issues/209 |
95
|
|
|
* @see https://github.com/smalot/pdfparser/issues/330 |
96
|
|
|
* @see https://github.com/smalot/pdfparser/issues/356 |
97
|
|
|
* @see https://github.com/smalot/pdfparser/issues/373 |
98
|
|
|
* @see https://github.com/smalot/pdfparser/issues/392 |
99
|
|
|
* @see https://github.com/smalot/pdfparser/issues/397 |
100
|
|
|
*/ |
101
|
|
|
public function testDecodeXrefStreamIssue356() |
102
|
|
|
{ |
103
|
|
|
$filename = $this->rootDir.'/samples/bugs/Issue356.pdf'; |
104
|
|
|
|
105
|
|
|
$parser = $this->getParserInstance(); |
106
|
|
|
$document = $parser->parseFile($filename); |
107
|
|
|
$pages = $document->getPages(); |
108
|
|
|
|
109
|
|
|
$this->assertStringContainsString('Ημερήσια έκθεση επιδημιολογικής', $pages[0]->getText()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testDecodeObjectHeaderIssue405() |
113
|
|
|
{ |
114
|
|
|
$filename = $this->rootDir.'/samples/bugs/Issue405.pdf'; |
115
|
|
|
|
116
|
|
|
$parser = $this->getParserInstance(); |
117
|
|
|
$document = $parser->parseFile($filename); |
118
|
|
|
$pages = $document->getPages(); |
119
|
|
|
|
120
|
|
|
$this->assertStringContainsString('Bug fix: PR #405', $pages[0]->getText()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Tests buggy behavior of decodeXrefStream. |
125
|
|
|
* |
126
|
|
|
* When PDF has more than one entry in the /Index area (for example by changing |
127
|
|
|
* the document description), only the first entry is used. |
128
|
|
|
* If the fix is not used the array returned by getDetails() contains only the entry |
129
|
|
|
* with the key 'Pages'. All other entries like 'Author', 'Creator', 'Title', |
130
|
|
|
* 'Subject' (which come from the 'Info' object) are not listed, because the |
131
|
|
|
* 'Info' object gets a wrong object id during parsing the data into the xref structure. |
132
|
|
|
* So the object id listed at the /Info entry is not valid and the data of the info object |
133
|
|
|
* cannot be loaded during executing Document::buildDetails(). |
134
|
|
|
* |
135
|
|
|
* @see https://github.com/smalot/pdfparser/pull/479 |
136
|
|
|
*/ |
137
|
|
|
public function testDecodeXrefStreamIssue479() |
138
|
|
|
{ |
139
|
|
|
$filename = $this->rootDir.'/samples/bugs/Issue479.pdf'; |
140
|
|
|
|
141
|
|
|
$parser = $this->getParserInstance(); |
142
|
|
|
$document = $parser->parseFile($filename); |
143
|
|
|
$details = $document->getDetails(); |
144
|
|
|
|
145
|
|
|
$this->assertArrayHasKey('Author', $details); |
146
|
|
|
$this->assertArrayHasKey('CreationDate', $details); |
147
|
|
|
$this->assertArrayHasKey('Creator', $details); |
148
|
|
|
$this->assertArrayHasKey('ModDate', $details); |
149
|
|
|
$this->assertArrayHasKey('Producer', $details); |
150
|
|
|
$this->assertArrayHasKey('Subject', $details); |
151
|
|
|
$this->assertArrayHasKey('Title', $details); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|