- Home
- Forum
- JavaScript - EJ 2
- ImportFormFields issue when trying to use it via the .net MVC service
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
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
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
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
Hello Sathiyaseelan,
Sure, take your time. Looking forward to hear the results of the investigation.
--
Wil
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
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
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
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
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
Hi Sathiyaseelan,
Sorry for not being clear, it has been resolved.
Thanks,
--
Wil
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
- 11 Replies
- 3 Participants
-
WV Wil van Antwerpen
- Sep 23, 2024 11:21 PM UTC
- Oct 9, 2024 01:12 PM UTC