Hi Sarita,
Thank you for interest in syncfusion products.
We cannot use XML data directly as data source, instead we can convert XML data into an equivalent enumerable class objects and then we have performed mail merge operation with respect to the fields available in the template document and convert the resultant document to pdf.
And also we have check the checkbox based on the field value using mailmerge even functionality in Essential DocIO. Kindly use the following code example to achieve the same.
I have attach the template document and xml file in the following link for your testing purpose:
http://www.syncfusion.com/downloads/support/forum/120667/ze/Template-1031257524
Code example:
'Load the xml file into the data table.
Dim xmlFile As XmlReader
xmlFile = XmlReader.Create("Customer_CheckBox.xml", New XmlReaderSettings())
Dim ds As New DataSet()
ds.ReadXml(xmlFile)
'Opens the input template document.
Dim document As New Syncfusion.DocIO.DLS.WordDocument("Template.docx")
' Using Merge events to do conditional formatting during runtime.
AddHandler document.MailMerge.MergeField, AddressOf MergeField_CheckBox
'perform the mail mergefunctionality.
document.MailMerge.Execute(ds.Tables(0))
Dim converter As New Syncfusion.DocToPDFConverter.DocToPDFConverter()
'Convert word document into PDF document
Dim pdfDoc As Syncfusion.Pdf.PdfDocument = converter.ConvertToPDF(document)
'Save the file as PDF.
pdfDoc.Save("DocToPDF")
<summary>
''' Handles the CheckBox event of the MergeField control.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="args">The <see cref="MergeFieldEventArgs"/> instance containing the event data.</param>
Private Sub MergeField_CheckBox(sender As Object, args As Syncfusion.DocIO.DLS.MergeFieldEventArgs)
' Check the field is city or not.
If args.FieldName = "City" Then
Dim checkBoxVlaue As String = args.FieldValue.ToString()
' Checks the field value is Boston or not.
If checkBoxVlaue = "Boston" Then
'Enbele the check box is true.
Dim paragraph As Syncfusion.DocIO.DLS.WParagraph = args.CurrentMergeField.OwnerParagraph
Dim checkBox As Syncfusion.DocIO.DLS.WCheckBox = GetCheckBox(paragraph)
If checkBox IsNot Nothing Then
checkBox.Checked = True
End If
End If
End If
End Sub
''' <summary>
''' Gets the CheckBox.
''' </summary>
''' <param name="paragraph">The paragraph.</param>
''' <returns></returns>
Private Function GetCheckBox(paragraph As Syncfusion.DocIO.DLS.WParagraph) As WCheckBox
For i As Integer = 0 To paragraph.ChildEntities.Count - 1
If TypeOf paragraph.ChildEntities(i) Is WCheckBox Then
Return TryCast(paragraph.ChildEntities(i), WCheckBox)
End If
Next
Return Nothing
End Function
Kindly try this and let us know if this helpful for you?
Regards,
Sivasubramani.V