- Он заменяет поле значения, даже если они не являются пустыми (т. е. необходимо заполнить «НП» только для пустых полей)
- Значение «НП» для пустых полей работает только на первой странице, для остальных страниц это не так работает
`import pdfrw
def fill_pdf_with_na(входной_путь, выходной_путь):
template_pdf = pdfrw.PdfReader(входной_путь)
Код: Выделить всё
for page_num in range(len(template_pdf.pages)):
annotations = template_pdf.pages[page_num]['/Annots']
if annotations is None:
continue
for annotation in annotations:
if annotation['/Subtype'] == '/Widget':
if annotation['/FT'] == '/Tx': # Text field
if '/V' not in annotation:
annotation.update(pdfrw.PdfDict(V="NA"))
elif annotation['/FT'] == '/Btn': # Button (checkbox)
if '/V' not in annotation:
annotation.update(pdfrw.PdfDict(V=pdfrw.PdfName('Yes')))
# Write the modified PDF to the output file
writer = pdfrw.PdfWriter()
writer.write(output_path, template_pdf)`
output_pdf_path = r"C:\fillpdf\output.pdf"
fill_pdf_with_na(input_pdf_path, output_pdf_path)
print(f"Заполненный PDF-файл сохранен в {output_pdf_path}")
Пожалуйста, помогите мне решить 2 проблемы
Подробнее здесь: https://stackoverflow.com/questions/785 ... ing-python