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. (Last updated on: June 24, 2019).
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 Oct 22,2019 01:48 PM UTC ASP.NET Core - EJ 2 3
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  


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