Skip to content
Discussion options

You must be logged in to vote

The issue here is that in PyMuPDF fields / widgets are kids of pages. To simulate pypdf2's behavior, one must use PyMuPDF's low-level functions - which still look similar enough to pypdf2.

With the low-level functions, you can access all of a PDF's object directly in a syntax close to PDF source code. So your above code would look like this:

import fitz, sys

def sort_fields(doc, field_xref):  # invoke with a field's cross ref number
    kids = doc.xref_get_key(field_xref, "Kids")  # are there kids?
    if kids[0] == "array":  # extract xref numbers from the kids array
        xrefs = list(map(int, kids[1][1:-1].replace("0 R", "").split()))
        return [sort_fields(doc, i) for i in xrefs

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by JorjMcKie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants