Hi Callam,Thank you for contacting Syncfusion support.At present, we do not have support for passing parameters to WebAPI method in PDF viewer control. Can you please provide us the details like what kind of parameters you are going to pass to the WebAPI controller of PDF viewer control and their usage in your project. So, that it will be helpful for us to analyze further on your requirement and assist you better.Regards,Aravinth
Hi
Do we now have support for passing parameters to WebAPI method in PDF viewer control?
Thanks
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentPath("F# Succinctly.pdf").AjaxRequestInitiate("ajaxRequestInitiate").Render()
function ajaxRequestInitiate(args) {
var viewer = document.getElementById("pdfviewer").ej2_instances[0];
if (args.JsonData.action == "Load") {
args.JsonData['documentId'] = '1001';
args.JsonData["moduleId"] = "1001";
viewer.setJsonData(args.JsonData);
}
}
|
Thanks, it worked
I have the next function, but I would like to send by parameter the full path to be uploaded in AWS S3.
[AcceptVerbs("Post")]
[HttpPost("ExportFormFields")]
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
[Route("[controller]/ExportFormFields")]
public void ExportFormFields([FromBody] Dictionary<string, string> jsonObject)
{
// Initialize the PDF Viewer object with memory cache object
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
if (jsonObject != null && jsonObject.ContainsKey("document"))
{
Console.WriteLine("Guardando en AWS");
RegionEndpoint bucketRegion = RegionEndpoint.USEast1;
// Configure the AWS SDK with your access credentials and other settings
var s3Client = new AmazonS3Client(_accessKey, _secretKey, bucketRegion);
string formPath = "aws-path/form-designer.pdf"; // full path to be uploaded in AWS S3.
byte[] bytes = Convert.FromBase64String(documentBase.Split(",")[1]);
using (MemoryStream stream = new MemoryStream(bytes))
{
var request = new PutObjectRequest
{
BucketName = _bucketName,
Key = formPath,
InputStream = stream,
};
// Upload the PDF document to AWS S3
var response = s3Client.PutObjectAsync(request).Result;
}
}
}
My questions are:
- How do I implement this in backend?
- How do I make the request in frontend with react if I want to use the ExportFormFields function when the users submit a form?
Hi Isaac,
Please refer to the
code snippet and sample provided for sending the path to the server when users
submit a form. In this sample, when the form is submitted the
`ajaxRequestInitiate` event is triggered, and we use this event to send the
path value to the server.
Code snippet in client-side (React):
function ajaxRequestInitiate(args) { if (args.JsonData['action'] === 'ExportFormFields') { console.log(args); args.JsonData['path'] = 'www.somepath.com'; // Provide the path here viewer.setJsonData(args.JsonData); } } |
Code snippet in server-side (ASP.NET.Core):
public IActionResult ExportFormFields([FromBody] Dictionary<string, string> jsonObject) { PdfRenderer pdfviewer = new PdfRenderer(_cache);
var path = jsonObject.ContainsKey("path") ? jsonObject["path"].ToString() : ""; Console.WriteLine(path);
string jsonResult = pdfviewer.ExportFormFields(jsonObject); return Content(jsonResult); } |
React sample: https://stackblitz.com/edit/react-mdw6fc-oybk5o?file=index.js
Web service sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ExportFormFieldAdditionalData25795401.zip
To send the path to the `ExportFormFields` method, follow these steps:
Hi Chinnamunia, thanks for your response.
My example it worked.