Skip to content

Commit a78ccf1

Browse files
committed
Avoid looping through all the page tree if there is no destination page
Signed-off-by: torakiki <[email protected]>
1 parent 72ed429 commit a78ccf1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

document-readers/pdf-reader/src/main/java/org/springframework/ai/reader/pdf/config/ParagraphManager.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ private int getPageNumber(PDOutlineItem current) throws IOException {
140140
return -1;
141141
}
142142
PDPage currentPage = current.findDestinationPage(this.document);
143-
PDPageTree pages = this.document.getDocumentCatalog().getPages();
144-
for (int i = 0; i < pages.getCount(); i++) {
145-
var page = pages.get(i);
146-
if (page.equals(currentPage)) {
147-
return i + 1;
143+
if(currentPage != null){
144+
PDPageTree pages = this.document.getDocumentCatalog().getPages();
145+
for (int i = 0; i < pages.getCount(); i++) {
146+
var page = pages.get(i);
147+
if (page.equals(currentPage)) {
148+
return i + 1;
149+
}
148150
}
149151
}
150152
return -1;

0 commit comments

Comments
 (0)