[
https://issues.apache.org/jira/browse/PDFBOX-6102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18040303#comment-18040303
]
Tilman Hausherr edited comment on PDFBOX-6102 at 11/24/25 12:17 PM:
--------------------------------------------------------------------
Might be a duplicate of PDFBOX-6036? Coincidentally, I just mentioned an issue
there from 1 year ago that you had created. Please try with a snapshot build:
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.7-SNAPSHOT/
was (Author: tilman):
Might be a duplicate of PDFBOX-6036? Coincidentally, I just mentioned an issue
there from 1 year ago that you had created.
> StackOverflowError when Copying 1000+ bookmarks
> -----------------------------------------------
>
> Key: PDFBOX-6102
> URL: https://issues.apache.org/jira/browse/PDFBOX-6102
> Project: PDFBox
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 3.0.6 PDFBox
> Reporter: Christian Haegele
> Priority: Major
> Attachments: 3000_bookmarks.pdf
>
>
> When copying 1000+ bookmarks from one document to another, a
> StackOverflowError is caused in PDFBox. The Exception doesn't occure in
> pdfbox 2.0.30.
>
>
> {code:java}
> @Test
> void pdfBoxBookmarksTest() throws IOException {
> Path outputFolder = Files.createTempDirectory("pdfBox30Test");
> Path bookmarkedPdf = outputFolder.resolve("bookmarked.pdf");
> try (PDDocument sourceDocument =
> Loader.loadPDF(stackOverflowPdfPath.toFile());
> PDDocument targetDocument =
> Loader.loadPDF(stackOverflowPdfPath.toFile())) {
> PDDocumentOutline sourceOutline =
> sourceDocument.getDocumentCatalog().getDocumentOutline();
> PDOutlineItem current = sourceOutline.getFirstChild();
> while (current != null) {
> PDPage sourcePage =
> current.findDestinationPage(sourceDocument);
> if (sourcePage != null) {
> PDPage copiedPage = targetDocument.importPage(sourcePage);
> // PdfUtilities.createBookmark(targetDocument,
> copiedPage, current.getTitle());
> // create bookmark
> var aBookmarkTitle = current.getTitle();
> if (aBookmarkTitle != null) {
> PDPageXYZDestination tempDestXyz = new
> PDPageXYZDestination();
> int pageIndex =
> targetDocument.getPages().indexOf(copiedPage); // 0-based
> tempDestXyz.setPageNumber(pageIndex + 1); // 1-based
> for destination
> tempDestXyz.setLeft((int)
> copiedPage.getCropBox().getLowerLeftX());
> tempDestXyz.setTop((int)
> copiedPage.getCropBox().getUpperRightY());
> tempDestXyz.setZoom(0);
> PDOutlineItem bookmark = new PDOutlineItem();
> bookmark.setDestination(tempDestXyz);
> bookmark.setTitle(aBookmarkTitle);
>
> targetDocument.getDocumentCatalog().getDocumentOutline().addLast(bookmark);
> }
> }
> current = current.getNextSibling();
> }
> targetDocument.save(bookmarkedPdf.toFile());
> } catch (IOException e) {
> Assertions.fail("Failed to create bookmarked PDF: " +
> e.getMessage());
> }
> } @Test
> void pdfBoxBookmarksTest() throws IOException {
> Path outputFolder = Files.createTempDirectory("pdfBox30Test");
> Path bookmarkedPdf = outputFolder.resolve("bookmarked.pdf");
> try (PDDocument sourceDocument =
> Loader.loadPDF(stackOverflowPdfPath.toFile());
> PDDocument targetDocument =
> Loader.loadPDF(stackOverflowPdfPath.toFile())) {
> PDDocumentOutline sourceOutline =
> sourceDocument.getDocumentCatalog().getDocumentOutline();
> PDOutlineItem current = sourceOutline.getFirstChild();
> while (current != null) {
> PDPage sourcePage =
> current.findDestinationPage(sourceDocument);
> if (sourcePage != null) {
> PDPage copiedPage = targetDocument.importPage(sourcePage);
> // PdfUtilities.createBookmark(targetDocument,
> copiedPage, current.getTitle());
> // create bookmark
> var aBookmarkTitle = current.getTitle();
> if (aBookmarkTitle != null) {
> PDPageXYZDestination tempDestXyz = new
> PDPageXYZDestination();
> int pageIndex =
> targetDocument.getPages().indexOf(copiedPage); // 0-based
> tempDestXyz.setPageNumber(pageIndex + 1); // 1-based
> for destination
> tempDestXyz.setLeft((int)
> copiedPage.getCropBox().getLowerLeftX());
> tempDestXyz.setTop((int)
> copiedPage.getCropBox().getUpperRightY());
> tempDestXyz.setZoom(0);
> PDOutlineItem bookmark = new PDOutlineItem();
> bookmark.setDestination(tempDestXyz);
> bookmark.setTitle(aBookmarkTitle);
>
> targetDocument.getDocumentCatalog().getDocumentOutline().addLast(bookmark);
> }
> }
> current = current.getNextSibling();
> }
> targetDocument.save(bookmarkedPdf.toFile());
> } catch (IOException e) {
> Assertions.fail("Failed to create bookmarked PDF: " +
> e.getMessage());
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]