[Python] mupdf mark field form widgets as read only

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    What I am trying to do is update form fields in a PDF with a value and then mark them as read-only so that they cannot be further edited.

    I have tried two approaches. use

    pdf.bake()


    This did not work for my use case, as post filling in data in the PDF I am doing an e-signature on the PDF. Now, if I use bake, all the signs show up on the first page when they are distributed across different pages.

    The second approach I tried is marking the widget read-only

    pdf_document = fitz.open("pdf", pdf_stream)
    READONLY_FLAG = 1 << 0
    processed_fields = set()
    for index, page in enumerate(pdf_document):
    for field in page.widgets():
    flag_image = False
    if not flag_image:
    if field.field_name not in processed_fields:
    print(f"non repeated name {field.field_name}, page {index}")
    processed_fields.add(field.field_name)
    field.field_flags |= READONLY_FLAG
    field.update()


    This works fine for most of the fields Except for fields that are repeated on multiple pages or on the same page. These fields are still editable. Other fields become non-editable.

    How to account for repeated fields as well?

    Continue reading...

Compartilhe esta Página