-
Hi, I am having problems with radio group form fields... Please tell me what I'm doing wrong? Codefrom pypdf import PdfReader, PdfWriter
from io import BytesIO
pdf_reader = PdfReader("./doc.pdf")
pdf_writer = PdfWriter()
pdf_writer.append(pdf_reader)
# Update form
total_pages = len(pdf_reader.pages)
for page_idx in range(total_pages):
pdf_writer.update_page_form_field_values(
pdf_writer.pages[page_idx],
{
Group1: "Choice1"
}
)
# Write the filled PDF to a BytesIO stream
output_stream = BytesIO()
pdf_writer.write(output_stream)
output_stream.seek(0)
# Save the filled PDF to a file
with open("./doc-filled.pdf", "wb") as output_file:
output_file.write(output_stream.getvalue()) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Please provide a complete example - the current code uses undefined variables and without a PDF file, providing support is nearly impossible. |
Beta Was this translation helpful? Give feedback.
-
My apologies, here is updated code and pdf file: from pypdf import PdfReader, PdfWriter
from io import BytesIO
pdf_reader = PdfReader("./radio.pdf")
pdf_writer = PdfWriter()
pdf_writer.append(pdf_reader)
# Update form
total_pages = len(pdf_reader.pages)
for page_idx in range(total_pages):
pdf_writer.update_page_form_field_values(
pdf_writer.pages[page_idx],
{
"Group1": "Choice2"
}
)
# Write the filled PDF to a BytesIO stream
output_stream = BytesIO()
pdf_writer.write(output_stream)
output_stream.seek(0)
# Save the filled PDF to a file
with open("./radio-filled.pdf", "wb") as output_file:
output_file.write(output_stream.getvalue()) I have checked available states and '/Choice2' value is present there, but still there is no checked option in resulting file... |
Beta Was this translation helpful? Give feedback.
The issue was resolved:
Thank you so much for support and have a nice day!