Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outline Iterator Object "open" property not applied after insertion #92

Open
King-of-Infinite-Space opened this issue Jun 10, 2024 · 3 comments

Comments

@King-of-Infinite-Space
Copy link

Hi devs, I want to add outlines that by default show first two levels and fold sub-levels.

I noticed two issues:

  1. After inserting the outline item, property open always prints false.
  2. Despite what is set and what is printed, the saved file always have all outlines unfolded.
const outlineIterator = doc.outlineIterator()

outlineIterator.insert({
  title: '1',
  open: true,
  uri: doc.formatLinkURI({
    page: 1,
    type: 'XYZ'
  }),
})

outlineIterator.prev()
console.log(outlineIterator.item())
// always prints "open: false"

outlineIterator.down()

outlineIterator.insert({
  title: '1.1',
  open: false,
  uri: doc.formatLinkURI({
    page: 1,
    type: 'XYZ'
  }),
})

outlineIterator.prev()
console.log(outlineIterator.item())

outlineIterator.down()

outlineIterator.insert({
  title: '1.1.1',
  open: false,
  uri: doc.formatLinkURI({
    page: 1,
    type: 'XYZ'
  }),
})

fs.writeFileSync('output.pdf', doc.saveToBuffer().asUint8Array())
const doc_output = mupdf.Document.openDocument(fs.readFileSync('output.pdf'), 'application/pdf')
for (const item of doc_output.loadOutline()) {
  console.log(item)
  // for all foldable items, open: true 
}
@King-of-Infinite-Space
Copy link
Author

The above point 1 can be ignored as I understand how PDF stores an outline item.

I think point 2 is due to an upstream issue in do_outline_update in pdf-outline.c
When an outline item is inserted, the open property is not being applied, and count always increment, resulting in all outline levels being unfolded.

The workaround is to do another pass to update the items after insertion, so that open is correctly applied.

@King-of-Infinite-Space King-of-Infinite-Space changed the title Outline Iterator Object "open" property not working Outline Iterator Object "open" property not applied after insertion Jul 15, 2024
@jamie-lemon
Copy link
Collaborator

@King-of-Infinite-Space Thanks for this - as this is an upstream issue (i.e. to do with core mupdf) would you mind reporting this bug here: https://bugs.ghostscript.com/ ? (feel free to tag this Issue on the bug and vice-versa)

@King-of-Infinite-Space
Copy link
Author

reported upstream Bug 707878

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

No branches or pull requests

2 participants