I'm filling my pdf form fields using python pypdf library and sending it to DocuSign for signing.Docusign converts the pdf fields to read-only but shrinks the formatting for it which is not what I want. Since my pdf is fillable form, if I fill it in chrome and use the chrome save_as_pdf feature. It makes a read-only pdf of my form, which DocuSign reads correctly without ruining the formatting of the pdf. Even when I try to change my pdf to readonly using pypdf writer flags, the pdf I get back has incorrect formatting.
I've tried all the possible pdf libraries to convert my pdf to a readonly pdf like the browser save_as_pdf functionality but all has been in vain. If I can convert my local file the same way as the browser and then push the bytes to DocuSign I'm hopeful it would work fine.
#Code to fill pdf and write to file
reader = PdfReader("wphg_form.pdf")
# reader = PdfReader("form.pdf")
writer = PdfWriter()
writer.append(reader)
writer.update_page_form_field_values(writer.pages[0], fields={
"DEPOT_NR": "1111111111",
})
with open("filled-out.pdf", "wb") as output_stream:
writer.write(output_stream)


Don't use PDF form fields, it won't work for this situation.
For something like that you will need to create 10 text fields, and not just one.
Basically, you can do this using a loop that adds them one after the other and pushes each field about 40 pixels to the right (you will need to figure out the exact number with trial and error).
You then fill the values and make it read only if you want that
Here is rough code to get you the idea: