We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Server side error when rendering pdf pages

I wrote a controller based on the example here: https://www.syncfusion.com/kb/10343/how-to-use-ej2-pdf-viewer-in-razor-pages, but adjusted the code for a web api controller. I have the following action (this.cache is an injected IMemoryCache):

        public IActionResult RenderPdfPages([FromBody] Dictionary<string, string> jsonObject)
            using (var pdfviewer = new PdfRenderer(this.cache))
                var jsonResult = pdfviewer.GetPage(jsonObject);
                return this.Content(JsonConvert.SerializeObject(jsonResult));

After a successful Load action is returned to the front end, the above method gets called with the following jsonObject parameter:


The jsonResult after GetPage is called is:

The given key '1' was not present in the dictionary.

While setting breakpoints in the code, I see that the memory cache does have the key that is provided in the jsonObject's hashId property with a value that is a syncfusion cache entry. So, there does not seem to be anything missing from the cache.

Do you have any more info about what the error could be describing?

2 Replies

AA Akshaya Arivoli Syncfusion Team November 12, 2019 01:21 PM UTC

Hi Nathan, 

Thank you for contacting Syncfusion support. 

We can reproduce the reported issue with the provided details, we will analyze further on this and update you with more details on November 15th, 2019. 


AA Akshaya Arivoli Syncfusion Team November 15, 2019 12:50 PM UTC

Hi Nathan, 

We have analyzed further on the reported behavior and found that loaded PDF document stream is removed from the PdfRenderer stream manager object if we initialize it in the ‘using’ keyword. In our architecture, we are rendering the pages in the PDF Viewer by on demand rendering method, if we initialize the PdfRenderer object in 'using' keyword and it will clear the loaded PDF document stream from the PdfRenderer stream manager object. So, on further processing for rendering or retrieving the annotation details from the loaded document and it's thrown the not found exception. We are maintaining the currently loaded document stream in our stream manager and it should in live to work further with that document. The stored document will be removed on unloading/closing that document. We can unload the PDF document manually by calling the unload() API available in PDF Viewer. Please find the below UG link for reference, 

We can resolve this by creating the PDF Viewer object without using keyword. We have created sample for the same and shared in the below location, 


Live Chat Icon For mobile
Up arrow icon