Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 17th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. def update_form_values(infile, outfile, newvals=None):
  2.     pdf = PdfFileReader(open(infile, 'rb'))
  3.     if "/AcroForm" in pdf.trailer["/Root"]:
  4.         pdf.trailer["/Root"]["/AcroForm"].update(
  5.             {NameObject("/NeedAppearances"): BooleanObject(True)})
  6.  
  7.     writer = PdfFileWriter()
  8.     # Used to make changes in the pdf-form visible
  9.     set_need_appearances_writer(writer)
  10.     if "/AcroForm" in writer._root_object:
  11.         writer._root_object["/AcroForm"].update(
  12.             {NameObject("/NeedAppearances"): BooleanObject(True)})
  13.  
  14.     for i in range(pdf.getNumPages()):
  15.         page = pdf.getPage(i)
  16.         try:
  17.             if newvals:
  18.                 writer.updatePageFormFieldValues(page, newvals)
  19.             else:
  20.                 writer.updatePageFormFieldValues(page,
  21.                                                 {k: f'#{i} {k}={v}'
  22.                                                 for i, (k, v) in enumerate(get_form_fields(infile).items())
  23.                                                 })
  24.             writer.addPage(page)
  25.         except Exception as e:
  26.             print(repr(e))
  27.             writer.addPage(page)
  28.  
  29.     with open(outfile, 'wb') as out:
  30.         writer.write(out)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top