Passed
Pull Request — master (#516)
by
unknown
02:09
created

PageTest::testDataTmFontInfoHasToBeIncluded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 31
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 38
rs 9.424
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;
34
35
use Smalot\PdfParser\Document;
36
use Smalot\PdfParser\Element\ElementMissing;
37
use Smalot\PdfParser\Font;
38
use Smalot\PdfParser\Page;
39
use Smalot\PdfParser\Config;
40
use Tests\Smalot\PdfParser\TestCase;
41
42
class PageTest extends TestCase
43
{
44
    public function testGetFonts(): void
45
    {
46
        // Document with text.
47
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
48
        $parser = $this->getParserInstance();
49
        $document = $parser->parseFile($filename);
50
        $pages = $document->getPages();
51
        $page = $pages[0];
52
53
        // the first to load data.
54
        $fonts = $page->getFonts();
55
        $this->assertTrue(0 < \count($fonts));
56
        foreach ($fonts as $font) {
57
            $this->assertTrue($font instanceof Font);
58
        }
59
        // the second to use cache.
60
        $fonts = $page->getFonts();
61
        $this->assertTrue(0 < \count($fonts));
62
63
        // ------------------------------------------------------
64
        // Document without text.
65
        $filename = $this->rootDir.'/samples/Document3_pdfcreator_nocompressed.pdf';
66
        $document = $parser->parseFile($filename);
67
        $pages = $document->getPages();
68
        $page = $pages[0];
69
70
        // the first to load data.
71
        $fonts = $page->getFonts();
72
        $this->assertEquals(0, \count($fonts));
73
        // the second to use cache.
74
        $fonts = $page->getFonts();
75
        $this->assertEquals(0, \count($fonts));
76
    }
77
78
    public function testGetFontsElementMissing(): void
79
    {
80
        $headerResources = $this->getMockBuilder('Smalot\PdfParser\Header')
81
            ->disableOriginalConstructor()
82
            ->getMock();
83
84
        $headerResources->expects($this->once())
85
            ->method('has')
86
            ->willReturn(true);
87
88
        $headerResources->expects($this->once())
89
            ->method('get')
90
            ->willReturn(new ElementMissing());
91
92
        $header = $this->getMockBuilder('Smalot\PdfParser\Header')
93
            ->disableOriginalConstructor()
94
            ->getMock();
95
96
        $header->expects($this->once())
97
            ->method('get')
98
            ->willReturn($headerResources);
99
100
        $page = new Page(new Document(), $header);
101
        $fonts = $page->getFonts();
102
103
        $this->assertEmpty($fonts);
104
        $this->assertEquals([], $fonts);
105
    }
106
107
    public function testGetFont(): void
108
    {
109
        // Document with text.
110
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
111
        $parser = $this->getParserInstance();
112
        $document = $parser->parseFile($filename);
113
        $pages = $document->getPages();
114
        $page = $pages[0];
115
116
        // the first to load data.
117
        $font = $page->getFont('R7');
118
        $this->assertTrue($font instanceof Font);
119
120
        $font = $page->getFont('ABC7');
121
        $this->assertTrue($font instanceof Font);
122
    }
123
124
    public function testGetText(): void
125
    {
126
        // Document with text.
127
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
128
        $parser = $this->getParserInstance();
129
        $document = $parser->parseFile($filename);
130
        $pages = $document->getPages();
131
        $page = $pages[0];
132
        $text = $page->getText();
133
134
        $this->assertTrue(150 < \strlen($text));
135
        $this->assertStringContainsString('Document title', $text);
136
        $this->assertStringContainsString('Lorem ipsum', $text);
137
138
        $this->assertStringContainsString('Calibri', $text);
139
        $this->assertStringContainsString('Arial', $text);
140
        $this->assertStringContainsString('Times', $text);
141
        $this->assertStringContainsString('Courier New', $text);
142
        $this->assertStringContainsString('Verdana', $text);
143
    }
144
145
    /**
146
     * @group memory-heavy
147
     *
148
     * @see https://github.com/smalot/pdfparser/pull/457
149
     */
150
    public function testGetTextPullRequest457(): void
151
    {
152
        // Document with text.
153
        $filename = $this->rootDir.'/samples/bugs/PullRequest457.pdf';
154
        $parser = $this->getParserInstance();
155
        $document = $parser->parseFile($filename);
156
        $pages = $document->getPages();
157
        $page = $pages[0];
158
        $text = $page->getText();
159
160
        $this->assertTrue(1000 < \strlen($text));
161
        $this->assertStringContainsString('SUPER', $text);
162
        $this->assertStringContainsString('VOORDEEL', $text);
163
        $this->assertStringContainsString('KRANT', $text);
164
        $this->assertStringContainsString('DINSDAG', $text);
165
        $this->assertStringContainsString('Snelfilterkoffie', $text);
166
        $this->assertStringContainsString('AardappelenZak', $text);
167
        $this->assertStringContainsString('ALL', $text);
168
    }
169
170
    public function testExtractRawData(): void
171
    {
172
        // Document with text.
173
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
174
        $parser = $this->getParserInstance();
175
        $document = $parser->parseFile($filename);
176
        $pages = $document->getPages();
177
        $page = $pages[0];
178
        $extractedRawData = $page->extractRawData();
179
180
        $btItem = $extractedRawData[0];
181
        $this->assertCount(3, $btItem);
182
        $this->assertArrayHasKey('t', $btItem);
183
        $this->assertArrayHasKey('o', $btItem);
184
        $this->assertArrayHasKey('c', $btItem);
185
186
        $this->assertEquals('BT', $btItem['o']);
187
188
        $tmItem = $extractedRawData[2];
189
190
        $this->assertcount(174, $extractedRawData);
191
        $this->assertCount(3, $tmItem);
192
193
        $this->assertArrayHasKey('t', $tmItem);
194
        $this->assertArrayHasKey('o', $tmItem);
195
        $this->assertArrayHasKey('c', $tmItem);
196
197
        $this->assertStringContainsString('Tm', $tmItem['o']);
198
        $this->assertStringContainsString('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
199
    }
200
201
    public function testExtractDecodedRawData(): void
202
    {
203
        // Document with text.
204
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
205
        $parser = $this->getParserInstance();
206
        $document = $parser->parseFile($filename);
207
        $pages = $document->getPages();
208
        $page = $pages[0];
209
        $extractedDecodedRawData = $page->extractDecodedRawData();
210
        $tmItem = $extractedDecodedRawData[2];
211
        $this->assertCount(174, $extractedDecodedRawData);
212
        $this->assertCount(3, $tmItem);
213
214
        $this->assertArrayHasKey('t', $tmItem);
215
        $this->assertArrayHasKey('o', $tmItem);
216
        $this->assertArrayHasKey('c', $tmItem);
217
218
        $this->assertStringContainsString('Tm', $tmItem['o']);
219
        $this->assertStringContainsString('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
220
221
        $this->assertCount(3, $tmItem);
222
        $this->assertArrayHasKey('t', $tmItem);
223
        $this->assertArrayHasKey('o', $tmItem);
224
        $this->assertArrayHasKey('c', $tmItem);
225
226
        $tjItem = $extractedDecodedRawData[3];
227
        $this->assertStringContainsString('TJ', $tjItem['o']);
228
        $this->assertStringContainsString('(', $tjItem['c'][0]['t']);
229
        $this->assertStringContainsString('D', $tjItem['c'][0]['c']);
230
        $this->assertStringContainsString('n', $tjItem['c'][1]['t']);
231
        $this->assertStringContainsString('0.325008', $tjItem['c'][1]['c']);
232
        $this->assertStringContainsString('(', $tjItem['c'][2]['t']);
233
        $this->assertStringContainsString('o', $tjItem['c'][2]['c']);
234
    }
235
236
    public function testExtractRawDataWithCorruptedPdf(): void
237
    {
238
        $this->expectException(\Exception::class);
239
        $this->expectExceptionMessage('Unable to find xref (PDF corrupted?)');
240
241
        $this
242
            ->getParserInstance()
243
            ->parseFile($this->rootDir.'/samples/corrupted.pdf')
244
            ->getPages();
245
    }
246
247
    public function testGetDataCommands(): void
248
    {
249
        // Document with text.
250
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
251
        $parser = $this->getParserInstance();
252
        $document = $parser->parseFile($filename);
253
        $pages = $document->getPages();
254
        $page = $pages[0];
255
        $dataCommands = $page->getDataCommands();
256
        $this->assertCount(168, $dataCommands);
257
258
        $tmItem = $dataCommands[1];
259
        $this->assertCount(3, $tmItem);
260
        $this->assertArrayHasKey('t', $tmItem);
261
        $this->assertArrayHasKey('o', $tmItem);
262
        $this->assertArrayHasKey('c', $tmItem);
263
264
        $this->assertStringContainsString('Tm', $tmItem['o']);
265
        $this->assertStringContainsString('0.999429 0 0 1 201.96 720.68', $tmItem['c']);
266
267
        $tjItem = $dataCommands[2];
268
        $this->assertCount(3, $tjItem);
269
        $this->assertArrayHasKey('t', $tjItem);
270
        $this->assertArrayHasKey('o', $tjItem);
271
        $this->assertArrayHasKey('c', $tjItem);
272
273
        $this->assertStringContainsString('TJ', $tjItem['o']);
274
        $this->assertStringContainsString('(', $tjItem['c'][0]['t']);
275
        $this->assertStringContainsString('D', $tjItem['c'][0]['c']);
276
        $this->assertStringContainsString('n', $tjItem['c'][1]['t']);
277
        $this->assertStringContainsString('0.325008', $tjItem['c'][1]['c']);
278
        $this->assertStringContainsString('(', $tjItem['c'][2]['t']);
279
        $this->assertStringContainsString('o', $tjItem['c'][2]['c']);
280
    }
281
282
    public function testGetDataTm(): void
283
    {
284
        // Document with text.
285
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
286
        $parser = $this->getParserInstance();
287
        $document = $parser->parseFile($filename);
288
        $pages = $document->getPages();
289
        $page = $pages[0];
290
291
        $dataTm = $page->getDataTm();
292
        $this->assertCount(81, $dataTm);
293
294
        $item = $dataTm[0];
295
        $this->assertCount(2, $item);
296
        $this->assertCount(6, $item[0]);
297
        $this->assertEquals(
298
            [
299
                '0.999429',
300
                '0',
301
                '0',
302
                '1',
303
                '201.96',
304
                '720.68',
305
            ],
306
            $item[0]
307
        );
308
309
        $this->assertStringContainsString('Document title', $item[1]);
310
        $item = $dataTm[2];
311
        $this->assertEquals(
312
            [
313
                '0.999402',
314
                '0',
315
                '0',
316
                '1',
317
                '70.8',
318
                '673.64',
319
            ],
320
            $item[0]
321
        );
322
323
        $this->assertStringContainsString('Calibri : Lorem ipsum dolor sit amet, consectetur a', $item[1]);
324
325
        $item = $dataTm[80];
326
        $this->assertEquals(
327
            [
328
                '0.999402',
329
                '0',
330
                '0',
331
                '1',
332
                '343.003',
333
                '81.44',
334
            ],
335
            $item[0]
336
        );
337
        $this->assertStringContainsString('nenatis.', $item[1]);
338
339
        // ------------------------------------------------------
340
        // Document is a form
341
        $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample1.pdf';
342
        $document = $parser->parseFile($filename);
343
        $pages = $document->getPages();
344
        $page = $pages[0];
345
        $dataTm = $page->getDataTm();
346
        $item = $dataTm[2];
347
        $this->assertCount(105, $dataTm);
348
        $this->assertCount(2, $item);
349
        $this->assertCount(6, $item[0]);
350
        $this->assertEquals(
351
            [
352
                '1',
353
                '0',
354
                '0',
355
                '1',
356
                '167.3',
357
                '894.58',
358
            ],
359
            $item[0]
360
        );
361
        $this->assertStringContainsString('MyName  MyLastName', $item[1]);
362
363
        $item = $dataTm[6];
364
        $this->assertEquals(
365
            [
366
                '1',
367
                '0',
368
                '0',
369
                '1',
370
                '681.94',
371
                '877.42',
372
            ],
373
            $item[0]
374
        );
375
        $this->assertStringContainsString('1/1/2020', $item[1]);
376
377
        $item = $dataTm[8];
378
        $this->assertEquals(
379
            [
380
                '1',
381
                '0',
382
                '0',
383
                '1',
384
                '174.86',
385
                '827.14',
386
            ],
387
            $item[0]
388
        );
389
        $this->assertStringContainsString('Purchase 1', $item[1]);
390
391
        // ------------------------------------------------------
392
        // Document is another form of the same type
393
        $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample2.pdf';
394
        $document = $parser->parseFile($filename);
395
        $pages = $document->getPages();
396
        $page = $pages[0];
397
        $dataTm = $page->getDataTm();
398
399
        $item = $dataTm[2];
400
        $this->assertCount(105, $dataTm);
401
        $this->assertCount(2, $item);
402
        $this->assertCount(6, $item[0]);
403
        $this->assertEquals(
404
            [
405
                '1',
406
                '0',
407
                '0',
408
                '1',
409
                '167.3',
410
                '894.58',
411
            ],
412
            $item[0]
413
        );
414
        $this->assertStringContainsString("Other'sName  Other'sLastName", $item[1]);
415
416
        $item = $dataTm[6];
417
        $this->assertEquals(
418
            [
419
                '1',
420
                '0',
421
                '0',
422
                '1',
423
                '681.94',
424
                '877.42',
425
            ],
426
            $item[0]
427
        );
428
        $this->assertStringContainsString('2/2/2020', $item[1]);
429
430
        $item = $dataTm[8];
431
        $this->assertEquals(
432
            [
433
                '1',
434
                '0',
435
                '0',
436
                '1',
437
                '174.86',
438
                '827.14',
439
            ],
440
            $item[0]
441
        );
442
        $this->assertStringContainsString('Purchase 2', $item[1]);
443
    }
444
445
    public function testDataTmFontInfoHasToBeIncluded(): void
446
    {
447
448
        $config = new Config();
449
        $config->setDataTmFontInfoHasToBeIncluded(true);
450
451
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
452
        $parser = $this->getParserInstance($config);
453
        $document = $parser->parseFile($filename);
454
        $pages = $document->getPages();
455
        $page = $pages[0];
456
        $dataTm = $page->getDataTm();
457
        $fonts = $page->getFonts();
458
459
        $item = $dataTm[0];
460
        $this->assertCount(4, $item);
461
        $this->assertEquals($item[2], 'R7');
462
        $this->assertEquals($item[3], '27.96');
463
        $this->assertArrayHasKey('R7', $fonts);
464
        $item = $dataTm[80];
465
        $this->assertCount(4, $item);
466
        $this->assertEquals($item[2], 'R14');
467
        $this->assertEquals($item[3], '11.04');
468
        $this->assertArrayHasKey('R7', $fonts);
469
470
        $filename = $this->rootDir.'/samples/InternationalChars.pdf';
471
        $document = $parser->parseFile($filename);
472
        $pages = $document->getPages();
473
        $page = $pages[0];
474
        $dataTm = $page->getDataTm();
475
        $fonts = $page->getFonts();
476
477
        $item = $dataTm[88];
478
        $this->assertEquals($item[2], 'C2_0');
479
        $this->assertEquals($item[3], '1');
480
        $this->assertArrayHasKey('C2_0', $fonts);
481
        foreach ($dataTm as $item) {
482
            $this->assertCount(4, $item);
483
        }
484
    }
485
486
    /**
487
     * Tests getDataTm with hexadecimal encoded document text.
488
     *
489
     * @see https://github.com/smalot/pdfparser/issues/336
490
     */
491
    public function testGetDataTmIssue336(): void
492
    {
493
        $filename = $this->rootDir.'/samples/bugs/Issue336_decode_hexadecimal.pdf';
494
        $document = $this->getParserInstance()->parseFile($filename);
495
        $pages = $document->getPages();
496
        $page = $pages[0];
497
        $dataTm = $page->getDataTm();
498
499
        $item = $dataTm[2];
500
        $this->assertCount(13, $dataTm);
501
        $this->assertCount(2, $item);
502
        $this->assertCount(6, $item[0]);
503
        $this->assertEquals(
504
            [
505
                '1',
506
                '0',
507
                '0',
508
                '1',
509
                '318.185',
510
                '665.044',
511
            ],
512
            $item[0]
513
        );
514
        $this->assertEquals('Lorem', $item[1]);
515
    }
516
517
    /**
518
     * Tests that getPages() only returns Page objects
519
     *
520
     * @see https://github.com/smalot/pdfparser/issues/331
521
     *
522
     * Sample pdf file provided by @Reqrefusion, see
523
     * https://github.com/smalot/pdfparser/pull/350#issuecomment-703195220
524
     */
525
    public function testGetPages(): void
526
    {
527
        $filename = $this->rootDir.'/samples/bugs/Issue331.pdf';
528
        $document = $this->getParserInstance()->parseFile($filename);
529
        $pages = $document->getPages();
530
531
        /*
532
         * The problem of issue #331 is fixed by the pull request of the issue #479.
533
         * The original Issue331.pdf was modified so for the updated version (actual
534
         * version) a new xref was added and now the valid /Index has the following value:
535
         *    [1 1 3 1 7 1 175 1 178 1 219 2]
536
         * This means, that there a 6 pairs containing the values for 'first object id'
537
         * and 'number of objects'. Till now only the first entry was used and so the
538
         * objects of all following entries gots a wrong id.
539
         * By the fix of issue #479 now the expected number of pages is counted.
540
         */
541
        $this->assertCount(3, $pages);
542
543
        foreach ($pages as $page) {
544
            $this->assertTrue($page instanceof Page);
545
        }
546
    }
547
548
    public function testGetTextXY(): void
549
    {
550
        // Document with text.
551
        $filename = $this->rootDir.'/samples/Document1_pdfcreator_nocompressed.pdf';
552
        $parser = $this->getParserInstance();
553
        $document = $parser->parseFile($filename);
554
        $pages = $document->getPages();
555
        $page = $pages[0];
556
        $result = $page->getTextXY(201.96, 720.68);
557
        $this->assertCount(1, $result);
558
        $this->assertCount(2, $result[0]);
559
        $this->assertEquals(
560
            [
561
                '0.999429',
562
                '0',
563
                '0',
564
                '1',
565
                '201.96',
566
                '720.68',
567
            ],
568
            $result[0][0]
569
        );
570
        $this->assertStringContainsString('Document title', $result[0][1]);
571
572
        $result = $page->getTextXY(201, 720);
573
        $this->assertCount(0, $result);
574
575
        $result = $page->getTextXY(201, 720, 1, 1);
576
        $this->assertCount(1, $result);
577
        $this->assertCount(2, $result[0]);
578
        $this->assertEquals(
579
            [
580
                '0.999429',
581
                '0',
582
                '0',
583
                '1',
584
                '201.96',
585
                '720.68',
586
            ],
587
            $result[0][0]
588
        );
589
        $this->assertStringContainsString('Document title', $result[0][1]);
590
591
        // ------------------------------------------------------
592
        // Document is a form
593
        $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample1.pdf';
594
        $document = $parser->parseFile($filename);
595
        $pages = $document->getPages();
596
        $page = $pages[0];
597
        $result = $page->getTextXY(167, 894, 1, 1);
598
        $this->assertCount(1, $result);
599
        $this->assertCount(2, $result[0]);
600
        $this->assertEquals(
601
            [
602
                '1',
603
                '0',
604
                '0',
605
                '1',
606
                '167.3',
607
                '894.58',
608
            ],
609
            $result[0][0]
610
        );
611
        $this->assertStringContainsString('MyName  MyLastName', $result[0][1]);
612
613
        $result = $page->getTextXY(681, 877, 1, 1);
614
        $this->assertStringContainsString('1/1/2020', $result[0][1]);
615
616
        $result = $page->getTextXY(174, 827, 1, 1);
617
        $this->assertStringContainsString('Purchase 1', $result[0][1]);
618
619
        // ------------------------------------------------------
620
        // Document is another form of the same type
621
        $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample2.pdf';
622
        $document = $parser->parseFile($filename);
623
        $pages = $document->getPages();
624
        $page = $pages[0];
625
        $result = $page->getTextXY(167, 894, 1, 1);
626
        $this->assertEquals(
627
            [
628
                '1',
629
                '0',
630
                '0',
631
                '1',
632
                '167.3',
633
                '894.58',
634
            ],
635
            $result[0][0]
636
        );
637
        $this->assertStringContainsString("Other'sName  Other'sLastName", $result[0][1]);
638
639
        $result = $page->getTextXY(681, 877, 1, 1);
640
        $this->assertStringContainsString('2/2/2020', $result[0][1]);
641
642
        $result = $page->getTextXY(174, 827, 1, 1);
643
        $this->assertStringContainsString('Purchase 2', $result[0][1]);
644
    }
645
646
    public function testExtractDecodedRawDataIssue450(): void
647
    {
648
        $filename = $this->rootDir.'/samples/bugs/Issue450.pdf';
649
        $parser = $this->getParserInstance();
650
        $document = $parser->parseFile($filename);
651
        $pages = $document->getPages();
652
        $page = $pages[0];
653
        $extractedDecodedRawData = $page->extractDecodedRawData();
654
        $this->assertIsArray($extractedDecodedRawData);
655
        $this->assertGreaterThan(3, \count($extractedDecodedRawData));
656
        $this->assertIsArray($extractedDecodedRawData[3]);
657
        $this->assertEquals('TJ', $extractedDecodedRawData[3]['o']);
658
        $this->assertIsArray($extractedDecodedRawData[3]['c']);
659
        $this->assertIsArray($extractedDecodedRawData[3]['c'][0]);
660
        $this->assertEquals(3, \count($extractedDecodedRawData[3]['c'][0]));
661
        $this->assertEquals('{signature:signer505906:Please+Sign+Here}', $extractedDecodedRawData[3]['c'][0]['c']);
662
    }
663
664
    public function testGetDataTmIssue450(): void
665
    {
666
        $filename = $this->rootDir.'/samples/bugs/Issue450.pdf';
667
        $parser = $this->getParserInstance();
668
        $document = $parser->parseFile($filename);
669
        $pages = $document->getPages();
670
        $page = $pages[0];
671
        $dataTm = $page->getDataTm();
672
        $this->assertIsArray($dataTm);
673
        $this->assertEquals(1, \count($dataTm));
674
        $this->assertIsArray($dataTm[0]);
675
        $this->assertEquals(2, \count($dataTm[0]));
676
        $this->assertIsArray($dataTm[0][0]);
677
        $this->assertEquals(6, \count($dataTm[0][0]));
678
        $this->assertEquals(1, $dataTm[0][0][0]);
679
        $this->assertEquals(0, $dataTm[0][0][1]);
680
        $this->assertEquals(0, $dataTm[0][0][2]);
681
        $this->assertEquals(1, $dataTm[0][0][3]);
682
        $this->assertEquals(67.5, $dataTm[0][0][4]);
683
        $this->assertEquals(756.25, $dataTm[0][0][5]);
684
        $this->assertEquals('{signature:signer505906:Please+Sign+Here}', $dataTm[0][1]);
685
    }
686
687
    public function testIsFpdf(): void
688
    {
689
        $filename = $this->rootDir.'/samples/Document1_foxitreader.pdf';
690
        $parser = $this->getParserInstance();
691
        $document = $parser->parseFile($filename);
692
        $pages = $document->getPages();
693
        $page = $pages[0];
694
        $this->assertFalse($page->isFpdf());
695
        $filename = $this->rootDir.'/samples/bugs/Issue454.pdf';
696
        $document = $parser->parseFile($filename);
697
        $pages = $document->getPages();
698
        $page = $pages[0];
699
        $this->assertTrue($page->isFpdf());
700
    }
701
702
    public function testGetPageNumber(): void
703
    {
704
        $filename = $this->rootDir.'/samples/Document1_foxitreader.pdf';
705
        $parser = $this->getParserInstance();
706
        $document = $parser->parseFile($filename);
707
        $pages = $document->getPages();
708
        $page = $pages[0];
709
        $this->assertEquals(0, $page->getPageNumber());
710
        $filename = $this->rootDir.'/samples/Document1_pdfcreator.pdf';
711
        $document = $parser->parseFile($filename);
712
        $pages = $document->getPages();
713
        $page = $pages[0];
714
        $this->assertEquals(0, $page->getPageNumber());
715
        $filename = $this->rootDir.'/samples/Document2_pdfcreator_nocompressed.pdf';
716
        $document = $parser->parseFile($filename);
717
        $pages = $document->getPages();
718
        $page = $pages[0];
719
        $this->assertEquals(0, $page->getPageNumber());
720
        $filename = $this->rootDir.'/samples/InternationalChars.pdf';
721
        $document = $parser->parseFile($filename);
722
        $pages = $document->getPages();
723
        $page = $pages[0];
724
        $this->assertEquals(0, $page->getPageNumber());
725
        $filename = $this->rootDir.'/samples/SimpleInvoiceFilledExample1.pdf';
726
        $document = $parser->parseFile($filename);
727
        $pages = $document->getPages();
728
        $page = $pages[0];
729
        $this->assertEquals(0, $page->getPageNumber());
730
        $filename = $this->rootDir.'/samples/bugs/Issue454.pdf';
731
        $document = $parser->parseFile($filename);
732
        $pages = $document->getPages();
733
        $page = $pages[0];
734
        $this->assertEquals(0, $page->getPageNumber());
735
        $page = $pages[1];
736
        $this->assertEquals(1, $page->getPageNumber());
737
        $page = $pages[2];
738
        $this->assertEquals(2, $page->getPageNumber());
739
        $page = $pages[3];
740
        $this->assertEquals(3, $page->getPageNumber());
741
    }
742
743
    public function testIssue454(): void
744
    {
745
        $filename = $this->rootDir.'/samples/bugs/Issue454.pdf';
746
        $parser = $this->getParserInstance();
747
        $document = $parser->parseFile($filename);
748
        $pages = $document->getPages();
749
        $page = $pages[0];
750
        $dataTm = $page->getDataTm();
751
        $this->assertIsArray($dataTm);
752
        $this->assertGreaterThan(0, \count($dataTm));
753
        $this->assertIsArray($dataTm[0]);
754
        $this->assertEquals(2, \count($dataTm[0]));
755
        $this->assertIsArray($dataTm[0][0]);
756
        $this->assertEquals(6, \count($dataTm[0][0]));
757
        $this->assertEquals(201.96, $dataTm[0][0][4]);
758
        $this->assertEquals(720.68, $dataTm[0][0][5]);
759
        $this->assertStringContainsString('Document title', $dataTm[0][1]);
760
        $textData = $page->getTextXY(201.96, 720.68);
761
        $this->assertStringContainsString('Document title', $textData[0][1]);
762
        $page = $pages[2];
763
        $dataTm = $page->getDataTm();
764
        $this->assertIsArray($dataTm);
765
        $this->assertGreaterThan(0, \count($dataTm));
766
        $this->assertIsArray($dataTm[0]);
767
        $this->assertEquals(2, \count($dataTm[0]));
768
        $this->assertIsArray($dataTm[0][0]);
769
        $this->assertEquals(6, \count($dataTm[0][0]));
770
        $this->assertEquals(67.5, $dataTm[0][0][4]);
771
        $this->assertEquals(756.25, $dataTm[0][0][5]);
772
        $this->assertStringContainsString('{signature:signer505906:Please+Sign+Here}', $dataTm[0][1]);
773
        $textData = $page->getTextXY(67.5, 756.25);
774
        $this->assertStringContainsString('{signature:signer505906:Please+Sign+Here}', $textData[0][1]);
775
    }
776
}
777