I have simplified this by create a PDF with two radio buttons, black and white, with white set to selected. The following code opens the original document (Black and white.pdf) and sets the selection to black. It then saves the document to a new final document (Black and white (saved to new file).pdf), and then appends the pdf to a new document and saves this (Black and white (appended and saved).pdf). The "saved and new" PDF has the correct selection, whilst the "appended and saved" PDF has lost the selection. Unfortunately, I need the second approach to work.
- Code: Select all
Dim doc1 As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument
Dim doc2 As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument("E:\Development\PDF Booking Forms\Black and White.pdf")
Dim formWidget As Spire.Pdf.Widget.PdfFormWidget = TryCast(doc2.Form, PdfFormWidget)
Dim radioButtonField As PdfRadioButtonListFieldWidget
For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1
field = TryCast(formWidget.FieldsWidget.List(i), PdfField)
If TypeOf field Is PdfRadioButtonListFieldWidget Then
RadioButtonField = TryCast(field, PdfRadioButtonListFieldWidget)
radioButtonField.WidgetWidgetItems.Item(0).Checked = True
End If
Next
'* Save the original document after setting the radio button value
doc2.SaveToFile("E:\Development\PDF Booking Forms\Black and White (saved to new file).pdf.pdf")
'* Append the amended document and save
doc1.AppendPage(doc2)
doc1.SaveToFile("E:\Development\PDF Booking Forms\Black and White (appended and saved).pdf")