Hello,
I'm trying to use a JSON string to pre-load some data into my fillable PDF document using the below code, however, the data doesn't load into the form and most of the time my app freezes up. I am using all of the latest nuget packages as of the date of posting. If you could please help me to understand how to use the ImportFormData function using JSON, preferably from a string (not a file), that would be amazing. Thank you!
public PDFFormFillerPage()
{
Title = "PDF";
SfPdfViewer pdfViewer;
pdfViewer = new SfPdfViewer();
pdfViewer.Toolbar.Enabled = false;
Grid grid = new Grid();
grid.Children.Add(pdfViewer);
Content = grid;
Stream fileStream;
PdfDocument document;
PdfTextBoxField textBoxField;
// Create a new PDF document
document = new PdfDocument();
document.PageSettings.Margins.All = 0;
//Add a page to the document
PdfPage page = document.Pages.Add();
//Create a textbox field and add the properties.
textBoxField = new PdfTextBoxField(page, "FirstName");
textBoxField.Bounds = new Syncfusion.Drawing.RectangleF(0, 0, 500, 100);
//Add the form field to the document.
document.Form.Fields.Add(textBoxField);
textBoxField.Text = "Test";
//Save the document to the stream
fileStream = new MemoryStream();
document.Save(fileStream);
//Close the document
document.Close(true);
//Load the PDF
pdfViewer.LoadDocument(fileStream);
fileStream.Close();
string jsonData = @"{'FirstName':'Mike'}";
byte[] byteArray = Encoding.Unicode.GetBytes(jsonData);
using (MemoryStream stream = new MemoryStream(byteArray))
{
pdfViewer.ImportFormData(stream, DataFormat.Json);
}
}