Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sat Jan 14, 2023 12:29 pm

I have a database and for each instance of an entity I wish to create a page in a PDF document. I use a base document and then populate the relevant data from the database. The final PDF has 1..n pages, with one page per entity. The base document contains two sets of radio buttons and the problem I am having is that having set the radio button to the appropriate selection, this selection is being lost when it is added or appended to the final document.

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")

highcroft
 
Posts: 3
Joined: Tue Nov 22, 2022 9:03 am

Mon Jan 16, 2023 2:55 am

Hello,

Thanks for your inquiry.
After investigation, I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREPDF-5730. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 951
Joined: Tue Mar 08, 2022 2:02 am

Mon Jan 16, 2023 7:33 pm

Hello Abel,

Thank you for your reply. Are you able to recommend a work around or a different approach? My basic requirement is to create a single PDF which comprises of 1..n copies of a single page PDF document. The original PDF document does contain radio buttons.

Best regards,

highcroft
 
Posts: 3
Joined: Tue Nov 22, 2022 9:03 am

Tue Jan 17, 2023 2:36 am

Hello,

Thanks for your feedback.
After doing more test, I found that the issue will occur when doc1 is just a new PdfDocument object and doc2 is spliced after doc1, however, I also found that if the doc1 loads a blank document with only 1 page and then appending doc2 behind doc1, this issue of losing radio button selected value doesn’t occur. Finally, delete the first page of the combined pdf document to get the desired result document.
I put the complete code below for your reference and attached the input pdf file.
If you have any issue, just feel free to contact us.
Code: Select all
'load the template file
        Dim doc1 As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument("../../data/test.pdf")

        Dim doc2 As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument("../../data/Black and White.pdf")
        Dim formWidget As Spire.Pdf.Widget.PdfFormWidget = TryCast(doc2.Form, Spire.Pdf.Widget.PdfFormWidget)
        Dim radioButtonField As PdfRadioButtonListFieldWidget


        For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1

            Dim 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("..\..\output\Black and White (saved to new file).pdf.pdf")


        '* Append the amended document and save

        doc1.AppendPage(doc2)

        'Remove the first pages
        doc1.Pages.RemoveAt(0)
        doc1.SaveToFile("..\..\output\new_____Black and White (appended and saved).pdf")


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 951
Joined: Tue Mar 08, 2022 2:02 am

Thu Mar 16, 2023 6:45 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.PDF 9.3.4 which fixes the issue with SPIREPDF-5730.
Please download the new version from the following links to test.

Website download link: https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html
Nuget download link: https://www.nuget.org/packages/Spire.PDF/9.3.4

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 951
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF