'PyPDF2 All Pages, Not sure how to write the loop
I am making an Offer generator loop as my first python learning project and I am running into a roadblock.
Everything is working perfectly fine except for the fact that PyPDF2 isn't getting all of the pages, only applying values from PySimpleGUI to the first page. On the output PDF, they don't show either.
import PySimpleGUIQt as sg
import PyPDF2
from PyPDF2 import PdfFileReader, PdfFileWriter
# Adding the Theme
sg.theme('SystemDefault')
# Determining the List
list1 = ('Pennsylvania', 'Texas', 'California')
# Layout, Data Entry
Left_Layout = [
[sg.Text('Offer Letter Generator', justification='center', size=(20, 1))],
[sg.Text('Candidate name', size=(15, 1)), sg.InputText('', size_px=(600, 30))],
[sg.Text('Position', size=(15, 1)), sg.InputText('', size_px=(600, 30))],
[sg.Text('Work Location', size=(15, 1)), sg.Combo(values=list1, default_value=list1[0], size_px=(600, 25))],
[sg.Text('Start Date', size=(15, 1)), sg.InputText('', size_px=(600, 30))],
[sg.Text('Manager Name', size=(15, 1)), sg.InputText('', size_px=(600, 30))],
[sg.Text('Manager Title', size=(15, 1)), sg.InputText('', size_px=(600, 30))],
[sg.Text('Salary', size=(15, 1)), sg.InputText('$', size_px=(600, 30))],
[sg.Checkbox('Profit Sharing?', default=False)],
[sg.Button('Cancel', size=(10, 1)), sg.Text('', size=(49.5, 0)), sg.Button('Generate', size=(10, 1))]
]
# GUI Window
window = sg.Window('Offer Generator', Left_Layout, size=(50, 100), return_keyboard_events=True)
event, values = window.Read()
window1 = sg.Window('Offer Details')
#Button Functions
while True:
event, values = window.Read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
elif event == 'Generate':
##PDF EDITOR
reader = PdfFileReader('OfferLetter.pdf')
writer = PdfFileWriter()
pages = reader.pages[0]
fields = reader.getFormTextFields()
writer.addPage(pages)
writer.updatePageFormFieldValues(
writer.getPage(0), {"Position": values[1], "CandidateName1": values[0],
"Location": values[2], "StartDate": values[3], "Salary": values[6],
}
)
with open("tempfile.pdf", "wb") as output_stream:
writer.write(output_stream)
print(values)
Honestly, I am suprised I got this to work, but this last part is stopping me from 100% completion of my goal. Any tips or help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
