-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
ENH: Flatten PDF forms #232
Comments
+1 A way to flatten a form would be excellent. I would like to avoid having another dependency for my code, which uses PyPDF2. But shipping filled in forms around the interwebz creates problems with a variety of vendors and their [I assume not based on PyPDF2] software. |
It would be great if PyPDF2 had the ability to fill in forms and flatten them! |
I also would really appreciate this |
(In progress) We can accomplish this by setting Bit Position 1 of the field flags. Ref: Table 8.70 of PDF 1,7 spec |
Setting a field read-only might be a way, however pdftk works differently; afaik it replaces each /Field instance with a simple text object. 😕 |
You're right, that's the better option. Should be able to implement that soon |
I agree. This would be totally awesome! |
Is there any update on this? |
I'm with @jamoham on this... for the same exact use case. |
+1 |
Any update on this? |
Can you flatten a file with PyPDF2 yet? I've not found anything on this being implemented. |
I do see some code to _flatten in the PdfFileReader, but not in the writer. Will someone be taking a swing at this? |
Rough bit of code if anyone needs to set fields to read-only prior to an update to the module (assumes you imported the whole module as PyPDF2). Works in a similar fashion to the existing
|
+1 for flattening, such as in pdftk! |
+1 for a method for flattening pdfs |
One thing I noticed with the approach of flattening/making forms read-only by setting the field flag bit to 1: when I try to merge resulting PDFs, only the values from the first document make it to the merged file. I don't think this is expected behavior.
|
Cross-posting this useful recipe by @Redjumpman: #506 Remember to update the form field name if you want to merge multiple documents made from the same template form. Else, the merged PDF result will have identical pages due to each document sharing the same field names. |
Can you confirm that this issue can get closed? |
without feed back I close this issue as fixed. Feel free to provides updates if yuo wan to reopen it. |
I don't think the original issue is closed: how do you make fields non-editable easily? The use case being taking a PDF with editable forms, filling out the forms and outputing a PDF with non-editable fields. |
What you are suggesting is not "flattening" thou. The output pdf will still present data fields (widgets) . |
@OpenNingia Can you provide a non-flat PDF file and its flattened version for review? |
Multiple pdf merged and flattened: One of the editable source: |
The flattening process is quite tough to compute (create XOBject with the good characteristics) modify the content to place them. |
since we have now #1864, flattening should be quite simple |
Can someone please provide a simple code snippet here for flattening a pdf? |
I have subclassed the Would you accept PR for this, and do you have any idea of the interface which would be best for implementation? I think this would be the easiest option, or there could be something more advanced, where you pass a list to be flattened, but all is the default, but I wouldn’t want to go too far on this. |
@matsavage What you should try is to convert the global |
I only did things this way to see if the flattening could be done, to save the effort of setting up the development environment on my machine, this is more the template than the PR Thanks for the advice, I’ll try and have a look at this some time |
Looking forward 😊 |
Looking forward for this feature! |
Honestly I haven’t been able to look at this since May, feel free to have your own attempt at implementing it if it’s something you need. |
At your marks.... get set ... go! 😉😄😄😄 |
I think it’s the one everyone wants, but no one wants to do |
Darn, I wouldn't even know where to start 🥴 |
pdftk provides the feature to embed the form fields' text in the pdf itself.
This is very useful if you want to use an editable pdf as a template to be filled by code.
from the pdftk manual:
usage example:
The text was updated successfully, but these errors were encountered: