Code Monkey home page Code Monkey logo

Comments (6)

jbarlow83 avatar jbarlow83 commented on May 20, 2024 1

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

from pikepdf.

OnlyFor avatar OnlyFor commented on May 20, 2024

Thanks again !

from pikepdf.

OnlyFor avatar OnlyFor commented on May 20, 2024

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

from pikepdf.

cepm-nate avatar cepm-nate commented on May 20, 2024

@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")?

from pikepdf.

jbarlow83 avatar jbarlow83 commented on May 20, 2024

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.

from pikepdf.

cepm-nate avatar cepm-nate commented on May 20, 2024

Thanks @jbarlow83 . I'll take a look.

from pikepdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.