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

Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows caching issue

We have implemented the PdfViewer using the Syncfusion EJ2 javascript component(@syncfusion/ej2). Also, the web service is implemented using .net core API. Now we are facing caching issues while taking the PDF. We have 5 pdf reports. When I took the first one it's showing as expected, after that, I will take the remaining ones it will still show the first loaded PDF. We have also implemented the unload method for clearing the memory cache and it's working as expected.  When we clear the "site data" , it is working as expected for some time. The issue exists when resource usage is exceeded.

NuGet package version  

Syncfusion.EJ2.PdfViewer.AspNet.Core.Windows: 17.3.0.17

npm version

"@syncfusion/ej2": "17.3.17"


API implementation


[HttpPost]
        [Route("api/[controller]/Load")]
        public async Task Upload([FromBody] Dictionary jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer(_cache);                
                MemoryStream stream=null;
                object jsonResult = new object();
                if (jsonObject != null && jsonObject.ContainsKey("document"))
                {
                    if (bool.Parse(jsonObject["isFileName"]))
                    {
                        var fileName = jsonObject["document"];
                        
                        var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(_appSettings.AzureFileServiceSettings.AccountName, _appSettings.AzureFileServiceSettings.AccessKey);

                        CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

                        CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

                        CloudFileShare share = fileClient.GetShareReference("xxxxxx");

                        if (await share.ExistsAsync(null, null))
                        {
                            CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                            CloudFile cfile = rootDir.GetFileReference(fileName);

                            if (await cfile.ExistsAsync(null, null))
                            {
                                stream = new MemoryStream();
                                await cfile.DownloadToStreamAsync(stream, null, null, null);
                            }
                        }                      
                    }
                    else
                    {
                        byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
                        stream = new MemoryStream(bytes);
                    }
                }
                if (stream == null)
                    return this.Content(jsonObject["document"] + " is not found");

                jsonResult = pdfviewer.Load(stream, jsonObject);
                return Content(JsonConvert.SerializeObject(jsonResult));
            }
            catch (Exception ex)
            {
                LogException(ex, "AccountInvoiceHeaderController", "Upload([FromBody] Dictionary jsonObject)");
                throw ex;
            }
        }

        [AcceptVerbs("Post")]
        [HttpPost]
        [Route("api/[controller]/RenderPdfPages")]
        public async Task RenderPdfPages([FromBody] Dictionary jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer(_cache);

                object jsonResult = pdfviewer.GetPage(jsonObject);

                return Content(JsonConvert.SerializeObject(jsonResult));
            }
            catch (Exception ex)
            {
                LogException(ex, "AccountInvoiceHeaderController", "RenderPdfPages([FromBody] Dictionary jsonObject)");
                throw ex;
            }
        }

        [AcceptVerbs("Post")]
        [HttpPost]
        [Route("api/[controller]/Download")]
        public async Task Download([FromBody] Dictionary jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer(_cache);
                string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
                return Content(documentBase);
            }
            catch (Exception ex)
            {
                LogException(ex, "PaymentController", "Download([FromBody] Dictionary jsonObject)");
                throw ex;
            }
        }

        [AcceptVerbs("Post")]
        [HttpPost]
        [Route("api/[controller]/PrintImages")]
        public async Task PrintImages([FromBody] Dictionary jsonObject)
        {
            try
            {
                PdfRenderer pdfviewer = new PdfRenderer(_cache);
                object pageImage = pdfviewer.GetPrintImage(jsonObject);
                return Content(JsonConvert.SerializeObject(pageImage));
            }
            catch (Exception ex)
            {
                LogException(ex, "AccountInvoiceHeaderController", "PrintImages([FromBody] Dictionary jsonObject)");
                throw ex;
            }
        }
        [AcceptVerbs("Post")]
        [HttpPost]
        [Route("api/[controller]/Unload")]
        public IActionResult Unload([FromBody] Dictionary jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);
            pdfviewer.ClearCache(jsonObject);
            return this.Content("Document cache is cleared");
        }



Client-side implementation


export class AccountInvoice {
  route: IRoute
  logger = LogManager.getLogger('AccountInvoice');
  pdfViewer: PdfViewer;
  constructor(private router: AppRouter) {
  }
  async activate(info: IRoute) {
    this.route = info;
    this.pdfViewer = new PdfViewer();
  }
  async attached() {
    this.pdfViewer.serviceUrl = window.location.protocol + "//" + window.location.host + '/api/xxxxxxxx';
    this.pdfViewer.documentPath = this.route.invoiceFileName;
    this.pdfViewer.toolbarSettings = { showTooltip: true, toolbarItems: ["PageNavigationTool", "SearchOption", "PrintOption", "DownloadOption"] };
    this.pdfViewer.enableThumbnail = false;
    this.pdfViewer.enableBookmark = false;
    this.pdfViewer.enableAnnotation = false;    
    //PDF Viewer control rendering starts
    this.pdfViewer.appendTo('#pdfViewer');
  }
  async deactivate() {
    this.pdfViewer.destroy();
  }

9 Replies

AA Akshaya Arivoli Syncfusion Team October 17, 2019 03:56 PM UTC

Hi Vipin, 

Thank you for contacting Syncfusion support. 

We are unable to reproduce the reported issue with the details provided in the incident with our online demo link. So can you please try this and provide us more details about your issue, sample in which the issue could be reproduced, replication steps and the error details , if you are still facing the issue these details will be helpful for us to investigate further on your issue and assist you better.  

Regards, 
Akshaya 



VI vipin October 21, 2019 02:03 PM UTC

We have created a sample application for replicating the issue.


Attachment: EJ2.PdfViewer_c78da8ae.zip


AA Akshaya Arivoli Syncfusion Team October 22, 2019 01:48 PM UTC

Hi Vipin, 
  
We have checked the provided sample and we are unable to reproduce the reported issue with that. We have shared the video demonstrating the same. 
  
  
Please try this and revert us with more details if you have any concerns on this. 
  
Regards,  
Akshaya  



DA Dario January 21, 2021 02:12 PM UTC

same issue with latest version of Pdf Viewer.
Resolved with custom document cache handle


AA Akshaya Arivoli Syncfusion Team January 22, 2021 11:00 AM UTC

  
Hi Dario, 
 
Thank you for your update. We were glad to know that the reported issue was resolved. 
 
Regards, 
Akshaya


HA Hafiz January 26, 2021 12:24 AM UTC

Hi, I'm also facing same problem.
I've opened a ticket for this issue.
Until it is resolve, I share here what I know and temporary countermeasure.

1) This problems only happen when pdf is loaded from MemoryStream (required when getting pdf from WebAPI).
2) Cause by PdfRenderer.Load() function which should generate a unique hashId for each pdf file. 
PdfRenderer pdfviewer = new PdfRenderer(_cache);    
var jsonResult = pdfviewer.Load(stream, jsonObject);
3) If we pass memorystream, PdfRenderer.Load() function will return same hashId into jsonResult no matter what pdf file we used.
This hashId is used as 'Key' in the _cache key-value pair which cause the _cache to contains only first pdf as the 2nd, 3rd and others pdf 'Key' is same as the 1st pdf.

As temporary countermeasure until this bug is solve, here what I've done:
1) Save the MemoryStream into local file, Load it then delete the file.
string filePath = _hostingEnvironment.WebRootPath + @"\tempFile.pdf";
using FileStream file = new FileStream(filePath, FileMode.Create, FileAccess.Write);
using Stream sm = await response.Content.ReadAsStreamAsync();
sm.CopyTo(file);
object jsonResult = pdfviewer.Load(filePath, jsonData);
System.IO.File.Delete(filePath);
return Content(JsonConvert.SerializeObject(jsonResult));


AA Akshaya Arivoli Syncfusion Team January 26, 2021 11:28 AM UTC

Hi RWEM , 
  
Thank you for contacting Syncfusion support. 

We were currently checking on your query with the provided details, we will update you with more details on January 27, 2021 
  
Regards, 
Akshaya 



VS Vasugi Sivajothi Syncfusion Team January 28, 2021 04:22 PM UTC

Hi RWEM,  
 
  
We have fixed the reported issue in our PDF Viewer source, So the fix will be included in our upcoming weekly nuget release on 3rd February  2021.  
 
  
Regards,  
Vasugi 



VS Vasugi Sivajothi Syncfusion Team February 3, 2021 05:41 PM UTC


Loader.
Live Chat Icon For mobile
Up arrow icon