Articles in this section
Category / Section

How to pass parameters from client to server-side of the PdfViewerControl

2 mins read

Essential JS 2 PDF Viewer

The Syncfusion PDF Viewer is a modern enterprise UI toolkit that has been built from the ground up to be lightweight, responsive, modular, and touch-friendly. It is available in other frameworks such as ASP.NET MVC, ASP.NET Core, JavaScript, Angular, and React.

Refer to the following UG link for getting started with the PdfViewerControl.

https://ej2.syncfusion.com/angular/documentation/pdfviewer/getting-started/

Passing parameters from client to server

PDF Viewer provides support to pass ID from the client to server using the serviceUrl property.  The custom serviceUrl should be used while passing parameters from client to server. A web service application in ASP.NET Core should be created, and that URL should be provided to the serviceUrl with the parameter that you need to pass to the server-side.

Refer to the following code.

export class AppComponent implements OnInit { 
    public service = 'http://localhost:58767/pdfviewer/xyz'; 
    public document = 'PDF_Succinctly.pdf'; 
    ngOnInit(): void { 
    } 
} 

In the preceding code, xyz is the parameter passing from the client to controller. 

Refer to the following KB link for creating web service application in ASP.NET Core.

https://www.syncfusion.com/kb/10346/how-to-create-pdf-viewer-web-service-application-in-asp-net-core

In the ASP.NET Core web service application, you should configure the route and template of Configure(IApplicationBuilder app, IHostingEnvironment env)in Startup.cs for passing the parameters from client to server. The ID should be mentioned before the action in a template like "{controller}/{id?}/{action}", because the ID will be added in the serviceUrl before appending the web action method. Refer to the following code. 

public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
        { 
            if (env.IsDevelopment()) 
            { 
                app.UseDeveloperExceptionPage(); 
            } 
            app.UseResponseCompression(); 
            app.UseMvc(routes => 
            { 
                routes.MapRoute("default", "{controller}/{id?}/{action}"); 
            });             
        } 

In the PdfViewerController.cs of the web service application, add the overloads for all web action methods as follows.   

public IActionResult Load(string id, [FromBody] Dictionary<string, string> jsonObject){ 
} 

 

Note:

In the preceding example, the string has been passed as a parameter from the client to controller and it will be included in all the requests

Angular Samplehttps://www.syncfusion.com/downloads/support/directtrac/general/ze/my-app-2093376304

Web API Servicehttps://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-pdfviewer-web-service_with_parameter146930884

Run the Web API service first, then that URL should be provided to the service URL property of the PdfViewerControl in Typescript file.   

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied