Skip to content

pdf_toc: Now returns if bookmarks are open#142

Merged
jeroen merged 1 commit intoropensci:masterfrom
trevorld:better-toc-data
Mar 15, 2026
Merged

pdf_toc: Now returns if bookmarks are open#142
jeroen merged 1 commit intoropensci:masterfrom
trevorld:better-toc-data

Conversation

@trevorld
Copy link
Contributor

closes #117

Claude Code claims (w.r.t. to the bookmarks are open field):

That's the only additional field the Poppler C++ public API exposes — page number, color, and font style would require accessing Poppler's internal OutlineItem API, which is beyond the public C++ bindings.

@jeroen
Copy link
Member

jeroen commented Mar 15, 2026

What does it mean for a bookmark to be "open" ?

@trevorld
Copy link
Contributor Author

What does it mean for a bookmark to be "open" ?

This is what poppler computes for if the the bookmark has "children" bookmarks then should these children be initially shown when looking at the bookmarks or should they be hidden.

In the actual pdf standard it overloads the COUNT bookmark field so that the subordinated books should initially be closed if it is a negative number and open if it is a positive number: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/pdfmark/pdfmark_Basic.html#bookmarks-out

@trevorld
Copy link
Contributor Author

From the pdf standard regarding COUNT:

If the value is positive, the bookmark is open, revealing its subordinates; if negative, the bookmark is closed, hiding its subordinates.

@jeroen
Copy link
Member

jeroen commented Mar 15, 2026

Is this information interesting for R users at all? It sounds more for GUIs?

@trevorld
Copy link
Contributor Author

Is this information interesting for R users at all? It sounds more for GUIs?

  • This information is somewhat marginal compared to other bookmark data like title and page numbers but I do have some R code to read/write pdf bookmark data and I could use this to slightly enhance the pdf bookmark data I read in particular the get_bookmarks_pdftools() function.
  • My pdftk-java backend gives me the page numbers (which is indeed much more important) but seemingly can't give me this open/closed information.
  • The typical use case where R users need to read and then write bookmarks is to restore pre-existing bookmarks to files processed by {qpdf} operations that strip bookmarks like pdf_combine() and pdf_subset().
  • https://trevorldavis.com/R/xmpdf/dev/reference/bookmarks.html
  • https://trevorldavis.com/R/xmpdf/dev/reference/cat_bookmarks.html

@jeroen jeroen merged commit 7e56df6 into ropensci:master Mar 15, 2026
10 checks passed
@jeroen
Copy link
Member

jeroen commented Mar 15, 2026

OK If it is useful to you, we can merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: 'pdf_toc()' returns more pdf bookmarks information

2 participants