Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Issue with flattening PDF
-
So this is a complete template as you can see clean but after processing
This is what it looks like
Name and first line of address only
after processing -
@CastroSATT I understand. I did test a little code with another pdf sample, and the output was read only. I'll test...
-
thanks for the help it’s on my snagging list
-
@CastroSATT Try this pdf with
from PyPDF2 import PdfFileReader, PdfFileWriter from PyPDF2.generic import BooleanObject, NameObject, IndirectObject, NumberObject TEMPLATE_PATH = 'SampleForm-1.pdf' OUTPUT_PATH = 'out1.pdf' data_dict = { 'Name':'test', 'Surname':'test' } if __name__ == '__main__': input_file = PdfFileReader(open(TEMPLATE_PATH, "rb")) output_file = PdfFileWriter() page = input_file.getPage(0) output_file.addPage(page) output_file.updatePageFormFieldValues(page, data_dict) page = output_file.getPage(0) for j in range(0, len(page['/Annots'])): writer_annot = page['/Annots'][j].getObject() print(writer_annot.get('/T')) # to know what to put in data_dict for field in data_dict: if writer_annot.get('/T') == None: continue if writer_annot.get('/T')[:len(field)] == field: writer_annot.update({ NameObject("/Ff"): NumberObject(1) # make ReadOnly }) output_stream = open(OUTPUT_PATH, "wb") output_file.write(output_stream) output_stream.close()
And you will see that the two fields from data_dict are readonly in out1.pdf
In JMA2.pdf,
print(writer_annot.get('/T')) # to know what to put in data_dict
gives None for the first line, perhaps the problem comes from there ⁉️
-
Yeah might be gonna download a demo of adobe try and remake the template not sure how to get rid of that none from there thanks so much will post an update in a few I’ve been using pdfscape to make the template and the template source (years ago) has been played with a few time after the years so maybe conflicts there some where but your right
Seems to work ok with that test one although would preferred to be uneditable but 1 thing at a time me thinks
-
@CastroSATT with the example, if you define all fields, the out pdf becomes uneditable
data_dict = { 'Name':'the', 'Surname':'king', 'email':'xxxx@yyyy.com', 'phone':'1234', 'Mobile':'1234', 'Street':'5th avenue', 'House':'3', 'Town':'NY', 'Postcode':'1234', 'Country':'Usa', 'Comments':'no' }
-
Still having a barney
-Tried your original template works
-Tried your template altered on 2 other form makers and they then have the issue after thatWeird so now gonna
Start with a blank form and 1 text box each see what happens thenI think the issue has something to do with the NONE
-When using pdfscrape I get 1 none (needs more testing)
-Using pdfelement 6 pro I get 2 none one and the top 2nd at the end
—Maybe something to do with the water mark provided by the software, I am reaching.Both using your working template (which has NO none)
-
@CastroSATT Good luck. I don't think I can help more. Sincerely, I don't know anything about pdf filling forms...
-
@CastroSATT I have run my little script on your JMA2.pdf and open the output pdf with PDF Expert app of Readdle, and fields are filled and read-only
-
Castro, I don't think you ever stated what your actual problem is. are you getting an error? Or is the saved form still editable? Or not filled?
What is your problem with None? Are you trying to fill the form with None? -
@JonB I think that his problem is that his output pdf is filled but still editable (with pdf editors). The problem of "None" comes from my little script where the first writer_annot.get('/T') gives None... It is not a real problem but with my sample template, there is no such "none" and the output file is filled and not editable. Thus, his post r fees to this None.