Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Removal of widgets, text is lost #2572

Closed
AndresEV22 opened this issue Aug 1, 2023 · 2 comments
Closed

Removal of widgets, text is lost #2572

AndresEV22 opened this issue Aug 1, 2023 · 2 comments

Comments

@AndresEV22
Copy link

When I use the method to delete all widgets from a PDF I lose all the text inside it, or when I use the widget.field_flags = fitz.PDF_FIELD_IS_READ_ONLY if I open the fields again they are editable.

To Reproduce (mandatory)

On read only fields, i save with this method:
for widget in widgets:
... logic to change the field value
widget.field_flags = fitz.PDF_FIELD_IS_READ_ONLY
widget.update()

and to delete it:
for widget in widgets:
widget.field_value = fields[widget.field_name] # type: ignore
widget.field_flags = fitz.PDF_FIELD_IS_READ_ONLY
widget.update()
page.delete_widget(widget)

Expected behavior (optional)

I expect text within a widget to be saved and the widget disappears or with the field flag when I reopen the PDF it's fields shouldn't be editable.

Your configuration (mandatory)

  • Windows 10 and arch linux
  • Python 3.11
  • PyMuPDF 1.22.5, installation method by pyproyect.toml.
@JorjMcKie
Copy link
Collaborator

JorjMcKie commented Aug 1, 2023

Deleting a widget, in general cannot be prevented by setting a field read-only.
That flag only prevents the widget being changed. You can still delete it independently from this.

Otherwise, I don't understand:
If you delete a widget, then it will be gone - together with everything associated.

@AndresEV22
Copy link
Author

AndresEV22 commented Aug 1, 2023

The thing I want to do is a common PDF operation called flattening. What this does is combine all text into one layer, removing the widgets and making it more hard to edit so we can protect the information that was filled out in the form. I know pdftk does it and also applications like Adobe Acrobat Reader.

This is mostly necessary to store the PDF file securely and increasing security on the document so it cannot be filled out later again.

Is this possible in pymupdf?

this is an exact example of flattening operation: https://pdfpro.com/blog/guides/how-to-flatten-a-pdf/

@pymupdf pymupdf locked and limited conversation to collaborators Aug 2, 2023
@JorjMcKie JorjMcKie converted this issue into discussion #2574 Aug 2, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants