Commit 3fe9e6e
authored
ROB: Handle missing destinations in reader (#840)
If a destination is missing, getDestinationPageNumber now returns -1
If `strict=False`, the first page is used as a fallback.
The code triggering the exception was
```python
from PyPDF2 import PdfFileReader
# https://github.com/mstamy2/PyPDF2/files/6045010/thyroid.pdf
with open("thyroid.pdf", "rb") as f:
reader = PdfFileReader(f)
bookmarks = pdf.getOutlines()
for b in bookmarks:
print(reader.getDestinationPageNumber(b) + 1) # page count starts from 0
```
The error message was:
PyPDF2.utils.PdfReadError: Unknown Destination Type: 0
Closes #604
Closes #8211 parent 5e86977 commit 3fe9e6e
3 files changed
+49
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
| 560 | + | |
| 561 | + | |
560 | 562 | | |
561 | 563 | | |
562 | 564 | | |
| |||
595 | 597 | | |
596 | 598 | | |
597 | 599 | | |
598 | | - | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
599 | 611 | | |
600 | 612 | | |
601 | 613 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
550 | 586 | | |
551 | 587 | | |
552 | 588 | | |
| |||
0 commit comments