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

[Feature request] add/modify bookmark #57

Closed
OnlyFor opened this issue Sep 17, 2019 · 6 comments
Closed

[Feature request] add/modify bookmark #57

OnlyFor opened this issue Sep 17, 2019 · 6 comments

Comments

@OnlyFor
Copy link

OnlyFor commented Sep 17, 2019

Amazing work !
Why not consider adding and editing bookmarks of pages (like PyPDF2),
thanks !

@jbarlow83
Copy link
Member

You already can manipulate the bookmarks data structure manually. Yes, I'd like to add this. Bookmarks have a lot of functionality associated.

@OnlyFor
Copy link
Author

OnlyFor commented Sep 18, 2019

Thanks again !

@OnlyFor
Copy link
Author

OnlyFor commented Nov 4, 2019

Finally i got what I wanted by parsing and imitating existing cases.

outlines = pikepdf.Dictionary({
    "/Type": pikepdf.Name("/Outlines"),
    "/Count": 0
})
for i in enumerate(ordered_bookmarks):
    child = pikepdf.Dictionary({
        "/A": pikepdf.Dictionary({
            "/D": pikepdf.Array([
                pdf_writer.root["/Pages"]["/Kids"][i[0]],
                pikepdf.Name("/Fit")
            ]),
            "/S": pikepdf.Name("/GoTo")
        }),
        "/Title": pikepdf.String(i[1]),
    })
    if "/First" not in outlines:
        outlines["/First"] = child
    else:
        outlines["/Last"]["/Next"] = child
    outlines["/Last"] = child
    outlines["/Count"] += 1
pdf_writer.root["/Outlines"] = outlines

@cepm-nate
Copy link

@OnlyFor , what is the variable ordered_bookmarks you are enumerating?

My quest is to find the page numbers that specifically a named bookmark refers to. I'm from the javascript world, so still trying to wrap my mind around python's style.

Do you have any examples that show a list of the bookmarks + their properties (namely just "Title" and "Page")?

@jbarlow83
Copy link
Member

Have a look at the PDF reference manual (ISO32000 2008) in section H.6 for a description of how the document outline works. In short it is a tree data structure and you have to decide how you want to traverse it. It's difficult to describe without diagrams. The reference manual is linked the pikepdf documentation.

@cepm-nate
Copy link

Thanks @jbarlow83 . I'll take a look.

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

3 participants