Skip to content

Use this function to flatten PDF widgets and make form fields non-editable. #4470

@winbina

Description

@winbina

my code:

@app.route('/fill', methods=['POST'])
def fill_field():
    suffix = str(uuid.uuid1())
    file_path = request.form.get('file_path')
    form = request.form.get('form_data')
    jd = json.loads(form)
    with open(file_path, 'rb') as reader:
        doc = mu.open(reader)
        for index in range(len(doc)):
            page = doc[index]
            for field in page.widgets():
                fn = field.field_name
                if jd.get(fn):
                    field.field_value = jd[fn]
                field.update()
        doc.ez_save(file_path + "." + suffix + ".pdf" ,
            deflate=False,
            deflate_images=False,
            deflate_fonts=False,
        )    # 优化文件结构)
        doc.close()
    return 'ok'

and run the code, i see the widget content is replaced, but the widget still can see it and edit it. how can i just show the content, but not the widget.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    not a bugnot a bug / user error / unable to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions