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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

148352 Oct 16,2019 09:48 AM UTC Feb 3,2021 05:41 PM UTC ASP.NET Core - EJ 2 9
loading
Tags: PDF Viewer
vipin
Asked On October 16, 2019 12:35 PM UTC

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();
  }

Akshaya Arivoli [Syncfusion]
Replied On 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 


vipin
Replied On October 21, 2019 02:03 PM UTC

We have created a sample application for replicating the issue.


Attachment: EJ2.PdfViewer_c78da8ae.zip

Akshaya Arivoli [Syncfusion]
Replied On 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  


Dario
Replied On January 21, 2021 02:12 PM UTC

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

Akshaya Arivoli [Syncfusion]
Replied On 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

RWEM ICT
Replied On 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));

Akshaya Arivoli [Syncfusion]
Replied On 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 


Vasugi Sivajothi [Syncfusion]
Replied On 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 


Vasugi Sivajothi [Syncfusion]
Replied On February 3, 2021 05:41 PM UTC


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon