How to send parameter from grid for loading pdf to pdf viewer.

I have grid. Grid data includes documents' informations such as name id. There is a extra column for row operation buttons which are view and delete document. My purpose is loading document after clicking viewdocwhich is located modal from database. Document is stored in database as a byte array. In additionejs-pdfviewer is located in modal. My question is how i can send document paremeter from grid for loading pdf to ejs-pdfviewer ?


7 Replies 1 reply marked as answer

DM Dhivyabharathi Mohan Syncfusion Team February 1, 2021 01:11 PM UTC

Hi Tumer, 
we have planned to create the sample based on the requirement. On clicking the grid row the click event will gets triggered in the client side. In that event , We will retrieve the text from the aguments and will load the same filename in the PDF Viewer client side load() method. Then using the file name, We can retrieve the document from DB in server side and load the same in the sever-side as stream 
Kindly let us know that these details match your criteria. We will provide the sample based on this by February 3rd, 2021. 
Regards, 
Dhivya. 



Tümer February 1, 2021 06:48 PM UTC

Hi,

Thank you for your response. I think sample will work according to the my needs.

Regards.


DM Dhivyabharathi Mohan Syncfusion Team February 2, 2021 05:36 PM UTC

Hi Tumer, 

Thank you for your update. As we mentioned earlier, we will provide further details on February 3rd, 2021. 

Regards, 
Dhivya. 



DM Dhivyabharathi Mohan Syncfusion Team February 3, 2021 03:47 PM UTC

Hi Tumer,  
 
Currently we are facing some complexity in achieving this. We will analyze further and provide more details on February 8, 2021. In the mean time, Kindly let us know that you want to open the PDF Viewer in new window or in a dialog box. It will be helpful for us to implement it in the  sample. 
 
Regards, 
Dhivya. 



DM Dhivyabharathi Mohan Syncfusion Team February 9, 2021 12:43 PM UTC

Hi Tumer, 
 
Thank you for your patience. 
 
As we mentioned, we have created the sample to load the document from database by clicking the buttons in grid. We have created one row in the grid, And we have a PDF Viewer button in that row. We need to click that button, our PDF Viewer will be opened inside a dialog box. PDF document will be retrieved as base64string from database using the document name and return as byte array to Load() web action for loading in PDF Viewer. We have shared the kb documentation to load the document from database. 
 
KB documentation link: 
 
Code snippet: 
 
public byte[] GetDocument(string documentID) 
        { 
            // Provide the database connection string (Right click in visual Studio -> Properties -> connectionString) 
            string constr = @"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Users\\XYZ\\Documents\\PdfList.mdf; Integrated Security = True; Connect Timeout = 30"; 
            System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(constr); 
            //Query to get the PDF document from database using the document name. 
            var query = "select PdfDocData from DocList where PdfDocName = '" + documentID + "'"; 
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query); 
            cmd.Connection = con; 
            con.Open(); 
            System.Data.SqlClient.SqlDataReader read = cmd.ExecuteReader(); 
            read.Read(); 
            //Retrieve the document data as base64 string 
            string base64 = (string)read["PdfDocData"]; 
            //Convert base64 string to byte array 
            byte[] byteArray = Convert.FromBase64String(base64); 
            return byteArray; 
 
        } 
 
 
 
 
Kindly try it and revert us if you have any concerns about this. 
 
Regards, 
Dhivya. 


Marked as answer

Tümer February 21, 2021 06:30 PM UTC

Thanks for sample code. I got pdf from database. But i get Document Reference pointer does not exist in the cache error when i applied to my project.



Attachment: Capture_c2e3582c.rar


DM Dhivyabharathi Mohan Syncfusion Team February 22, 2021 11:29 AM UTC

Hi Tumer,  
 
We will store the document in the cache based on the hashid during the initial loading of the pdf file. Then on scrolling or navigating to that page we will send the hashid and required page number from the client-side and then we will retrieve the page details with the hashid on the server-side. So the cache is required for rendering the PDF pages in our PDF Viewer control. We suspect that the cache is missed in all the controller methods or it is not been included in a startup.cs class. So, that the issue occurs. We request you to use the _cache in all the controller method as like below code snippet: 
 
 
  private IMemoryCache _cache; 
 
        public PdfViewerController(IHostingEnvironment hostingEnvironment, IMemoryCache cache) 
        { 
            _hostingEnvironment = hostingEnvironment; 
            _cache = cache; 
        } 
public IActionResult Load([FromBody] Dictionary<string, string> jsonObject) 
        { 
            PdfRenderer pdfviewer = new PdfRenderer(_cache); 
            MemoryStream stream = new MemoryStream(); 
            object jsonResult = new object(); 
            if (jsonObject != null && jsonObject.ContainsKey("document")) 
            { 
 
                if (bool.Parse(jsonObject["isFileName"])) 
                { 
                    //Get the PDF document from Database 
                    byte[] docData = GetDocument(jsonObject["document"]); 
                    stream = new MemoryStream(docData); 
                } 
                else 
                { 
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]); 
                    stream = new MemoryStream(bytes); 
                } 
            } 
            jsonResult = pdfviewer.Load(stream, jsonObject); 
            return Content(JsonConvert.SerializeObject(jsonResult)); 
        } 
 
 
 
Add the below line in startup.cs file 
 
 
public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddMemoryCache(); 
            services.AddMvc(). 
           AddJsonOptions(options => 
           { 
                // JSON serialization not defaulting to default? 
                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); 
           }); 
        } 
 
 
 
If the above-provided details do not resolve your issue, Kindly provide more details or a simple sample for replicating the issue on our end. So that would be helpful for us to analyze more and assist you better.  
 
Regards, 
Dhivya. 


Loader.
Up arrow icon