ImportFormFields issue when trying to use it via the .net MVC service

Hi,

When trying to import form fields using the standalone version of the pdf viewer there are no issues. It works fine.

However trying to use the same code on the pdf viewer that uses the .net MVC backend fails.
The code used is based on the help as documented here: https://ej2.syncfusion.com/documentation/pdfviewer/how-to/create-pdfviewer-service

For the C# code I am using the following code for the function that gets called:


        [System.Web.Mvc.HttpPost]
        public object ImportFormFields(Dictionary<string, string> jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer();
                object jsonResult = pdfviewer.ImportFormFields(jsonObject);
                return (JsonConvert.SerializeObject(jsonResult));
            }
            catch (Exception ex)
            {
                // Log the exception message
                System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);
                return new HttpStatusCodeResult(500, ex.Message);
            }
        }

The problem however is that the code just exits on the line with "pdfviewer.ImportFormFields". No exception is triggered and no results in regards to the viewer.
Note that similar code for the exportFormFields works fine when using with the .net service. It's just that it doesn't work for the importFormFields.

Below I have a zip with example code of the project. It also comes with a index.html / index.js that has a button to do the merge. The relevant code from that looks like:

var pdfviewer = new ej.pdfviewer.PdfViewer({
  documentPath: 'form-filling-document.pdf',
  serviceUrl: 'api/pdfviewer',
});
ej.pdfviewer.PdfViewer.Inject(
  ej.pdfviewer.TextSelection,
  ej.pdfviewer.TextSearch,
  ej.pdfviewer.Print,
  ej.pdfviewer.Navigation,
  ej.pdfviewer.Toolbar,
  ej.pdfviewer.Magnification,
  ej.pdfviewer.Annotation,
  ej.pdfviewer.FormDesigner,
  ej.pdfviewer.FormFields
);

pdfviewer.appendTo('#pdfViewer');

document.getElementById('id').addEventListener('click', function () {
  pdfviewer.importFormFields('{"name":"Roger","email":"Rabbit","gender":"Unspecified","dob":"","state":"Alabama","newsletter":"Yes"}');
});


Clearly something is wrong.. it might be my code, it might be something else.
At the moment I'm stuck.

Any help appreciated.

Thanks!
--
Wil


Attachment: sfWebPdfViewer20240924_85650442.zip

11 Replies

SK Sathiyaseelan Kannigaraj Syncfusion Team September 25, 2024 11:35 AM UTC

Hi Wil Van,

Thank you for reaching out. We were able to reproduce the reported issue “
Unable to import the form field in server backed PDF Viewer” and suspect this to be a defect. We will analyze further on this and update you with more details on September 27, 2024.


Regards,
S



WV Wil van Antwerpen September 25, 2024 01:46 PM UTC

Hello Sathiyaseelan,

Thank you for confirming that you are able to reproduce the problem.
Looking forward to the update. Really hoping that there is a solution for this.

Thanks!
--
Wil



SK Sathiyaseelan Kannigaraj Syncfusion Team September 27, 2024 03:02 PM UTC

Hi Wil van,

Sorry for the inconvenience. We are still validating the reported scenario, we need two more days to investigate further and will provide further details on or before 
October 03, 2024.

We thank you for your patience and understanding. 


Regards,
Sathiyaseelan K



WV Wil van Antwerpen September 27, 2024 03:39 PM UTC

Hello Sathiyaseelan,

Sure, take your time. Looking forward to hear the results of the investigation.


--
Wil



US Umamageshwari Shanmugam Syncfusion Team October 4, 2024 02:24 PM UTC

Hi Wil van,

Upon further analysis, it appears that the data value was not correctly set at the sample level. Therefore, you need to make the following changes to the controller file to import the provided data into the server-side PDF viewer. Here is the code snippet and sample for this.
 

 Code snippet:

  

    public IActionResult ImportFormFields([FromBody] Dictionary<string, string> jsonObject)

    {

        PdfRenderer pdfviewer = new PdfRenderer(_cache);

        var importFormFieldData = GetDocumentPath(jsonObject["data"]);

        if (importFormFieldData == string.Empty)

        {

            var importformFieldDataObject = JsonConvert.DeserializeObject(jsonObject["data"]);

            if (importformFieldDataObject != null)

            {

                jsonObject["data"] = importformFieldDataObject.ToString();

            }

        }

        else

        {

            jsonObject["data"] = importFormFieldData;

        }

        object jsonResult = pdfviewer.ImportFormFields(jsonObject);

        return Content(JsonConvert.SerializeObject(jsonResult));

    }


 Javascript sample: https://stackblitz.com/edit/4aqkiu-317stm?file=index.html,index.js
 

 Web service sample: Webservice27.1.51





WV Wil van Antwerpen replied to Umamageshwari Shanmugam October 7, 2024 04:13 PM UTC

Hello Umamageshwari,


Thank you.

Sadly though I can't test it at the moment as the code is not using the MVC Framework and while I tried to adapt the new code to that, it still did not work for me.
Will see if I can rewrite the service that is here to asp.net core, but that might not be an option on short notice.

--
Wil



WV Wil van Antwerpen October 7, 2024 04:40 PM UTC

Hi,

Sorry I should of course show what code I tried. It's hard to guess what's wrong if I don't provide details.

Here's the code that does not work for me.


        [System.Web.Mvc.HttpPost]
        public object ImportFormFields(Dictionary<string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            var importFormFieldData = GetDocumentPath(jsonObject["data"]);
            if (importFormFieldData == string.Empty)
            {
                var importformFieldDataObject = JsonConvert.DeserializeObject(jsonObject["data"]);
                if (importformFieldDataObject != null)
                {
                    jsonObject["data"] = importformFieldDataObject.ToString();
                }
            }
            else
            {
                jsonObject["data"] = importFormFieldData;
            }
            object jsonResult = pdfviewer.ImportFormFields(jsonObject);
            return JsonConvert.SerializeObject(jsonResult);
        }


I'm sure it's something simple that I'm doing wrong.

--
Wil



WV Wil van Antwerpen replied to Wil van Antwerpen October 7, 2024 05:30 PM UTC

Never mind, figured it out eventually.

I was missing a "GetPlainText" on the return line.
So in the end, the code now looks like:


        [System.Web.Mvc.HttpPost]
        public object ImportFormFields(Dictionary<string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            var importFormFieldData = GetDocumentPath(jsonObject["data"]);
            if (importFormFieldData == string.Empty)
            {
                var importformFieldDataObject = JsonConvert.DeserializeObject(jsonObject["data"]);
                if (importformFieldDataObject != null)
                {
                    jsonObject["data"] = importformFieldDataObject.ToString();
                }
            }
            else
            {
                jsonObject["data"] = importFormFieldData;
            }
            object jsonResult = pdfviewer.ImportFormFields(jsonObject);
            return (GetPlainText(JsonConvert.SerializeObject(jsonResult)));
        }


Thanks!
--
Wil



SK Sathiyaseelan Kannigaraj Syncfusion Team October 8, 2024 03:59 PM UTC

Hi Wil Van,

Thank you for the update. Please confirm whether the issue has been resolved or if you are still experiencing any problems. Based on your confirmation, we will investigate further and provide a solution.


Regards,
Sathiyaseelan K



WV Wil van Antwerpen October 8, 2024 04:09 PM UTC

Hi Sathiyaseelan,


Sorry for not being clear, it has been resolved.

Thanks,
--
Wil




SK Sathiyaseelan Kannigaraj Syncfusion Team October 9, 2024 01:12 PM UTC

Hi Wil Van,

We're pleased to hear that your issue has been resolved. Don't hesitate to reach out if you need any further assistance.


Regards,
Sathiyaseelan K


Loader.
Up arrow icon