Avoid looping through all the page tree if there is no destination page (#3396)

* Avoid looping through all the page tree if there is no destination page

Fixes: #3396

Auto-cherry-pick to 1.0.x

Signed-off-by: torakiki <andrea.vacondio@gmail.com>
This commit is contained in:
Andrea Vacondio
2025-05-30 19:11:20 +02:00
committed by GitHub
parent 50109167fa
commit 7c674c9a6b

View File

@@ -140,11 +140,13 @@ public class ParagraphManager {
return -1;
}
PDPage currentPage = current.findDestinationPage(this.document);
PDPageTree pages = this.document.getDocumentCatalog().getPages();
for (int i = 0; i < pages.getCount(); i++) {
var page = pages.get(i);
if (page.equals(currentPage)) {
return i + 1;
if (currentPage != null) {
PDPageTree pages = this.document.getDocumentCatalog().getPages();
for (int i = 0; i < pages.getCount(); i++) {
var page = pages.get(i);
if (page.equals(currentPage)) {
return i + 1;
}
}
}
return -1;