-
Notifications
You must be signed in to change notification settings - Fork 66
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
PdfDocument::bookmarks::iter
skips the root bookmark
#120
Comments
Also Codeprintln!("root: {}", root.title().unwrap());
for (idx, bookmark) in root.iter_all_descendants().enumerate() {
println!(" {idx}: {}", bookmark.title().unwrap());
} Output
But |
Hi @xVanTuring , thank you for reporting the issue. Let's focus on this issue first, since you have a work-around for your other issue. Are you able to provide a non-copyrighted sample document that demonstrates the problem? |
Bookmark.pdf |
I agree, the traversal methodology used by the use pdfium_render::prelude::*;
pub fn main() -> Result<(), PdfiumError> {
let bindings =
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("../pdfium/"))
.or_else(|_| Pdfium::bind_to_system_library())?;
let pdfidum = Pdfium::new(bindings);
let document = pdfidum.load_pdf_from_file("Bookmark.pdf", None)?;
let bookmarks = document.bookmarks();
println!("root: {}", bookmarks.root().unwrap().title().unwrap());
println!("Iter root direct children:");
for (idx, bookmark) in bookmarks.root().unwrap().iter_direct_children().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
println!("Iter root all descendants:");
for (idx, bookmark) in bookmarks.root().unwrap().iter_all_descendants().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
println!("Iter entire tree from root:");
for (idx, bookmark) in bookmarks.iter().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
Ok(())
} and applying it to your sample document, I now get the following output:
which looks more like the expected result. |
Extended sample code to check siblings as well: use pdfium_render::prelude::*;
pub fn main() -> Result<(), PdfiumError> {
let bindings =
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("../pdfium/"))
.or_else(|_| Pdfium::bind_to_system_library())?;
let pdfidum = Pdfium::new(bindings);
let document = pdfidum.load_pdf_from_file("Bookmark.pdf", None)?;
let bookmarks = document.bookmarks();
println!("root: {}", bookmarks.root().unwrap().title().unwrap());
println!("Iter root siblings:");
for (idx, bookmark) in bookmarks.root().unwrap().iter_siblings().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
println!("Iter root direct children:");
for (idx, bookmark) in bookmarks.root().unwrap().iter_direct_children().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
println!("Iter root all descendants:");
for (idx, bookmark) in bookmarks.root().unwrap().iter_all_descendants().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
println!("Iter entire tree from root:");
for (idx, bookmark) in bookmarks.iter().enumerate() {
println!("{idx}: {}", bookmark.title().unwrap());
}
Ok(())
} Made a small change to
Updated README. Ready to release as part of 0.8.16. |
The doc says it
starting from the top-level root bookmark.
I assume that means including the root(first) bookmark.Code
Output
The text was updated successfully, but these errors were encountered: