title: How to update a field with PyPDF2
body: <p>I'm trying to make a pdf generator and I'm almost there but can't figure out the final step of updating the form field.</p>
  
  <p>I'm using PyPDF2 in a Windows environment with Python 3.6</p>
  
  <p>The first step is to download the pdf (of which there are many, though they are all very similar and they all have the same form fields). The following code will then open the pdf and write a new one. My belief is that if I update the dictionary of form fields and write that dictionary to the new file then it will make the change I want. Problem is I can't work out how to put into effect the updated dictionary.</p>
  
  <pre><code>pdf = open(file, 'rb')
  flObj = PdfFileReader(pdf)
  flObj.decrypt(password)
  dict = flObj.getFormTextFields()
  writer = PdfFileWriter()
  outputstream = open(my_file, 'wb')
  dict['DB_Code'] = '2809785' #as an example
  for i in range(flObj.getNumPages()):
      writer.addPage(flObj.getPage(i))
  writer.write(outputstream)
  outputstream.close()
  </code></pre>
  
  <p>I can see in the <a href="https://pythonhosted.org/PyPDF2/PdfFileWriter.html" rel="nofollow noreferrer">documentation</a> of PyPDF2 that there is the updatePageFormFieldValues(page, fields) however the dictionary returned by the getFormTextFields function doesn't give the pages that it applies to (the fields are spread across 4 pages in the pdf always), so I'm not quite sure how to apply this.</p>
  
  <p>I have looked at a number of other questions and solutions, such as <a href="https://www.reddit.com/r/Python/comments/41n1rm/writing_to_pdfs/" rel="nofollow noreferrer">this</a>, however don't feel they fit my needs.</p>
  
  <p>Thanks in advance.</p>