Optimization of PDF Viewer Service

Hi, the Load method in PDF Viewer Control is taking 9 seconds for a PDF file of 10 MB to load. How can we optimize it to reduce this time to upto 1 second? 
I am first reading all bytes from the file, converting it into stream and then loading the file for preview.
The code for reference is given below.

if (jsonObject != null && (jsonObject.ContainsKey("document") || jsonObject.ContainsKey("documentId")))
{
     string documentPath = fileName;
     // Get byte array
     var bytes = RepositoryFactory.GetRepositoryFatoru().GetFileRepository(organization.OrganizationId).GetFileBytes(documentPath);
     if (bytes != null)
     {
           stream = new MemoryStream(bytes);
     }
     else
     {
           return (documentPath + " is not found");
     }
}
jsonResult = pdfviewer.Load(stream,jsonObject);
var response = JsonConvert.SerializeObject(jsonResult); 
return response;

3 Replies

AA Akshaya Arivoli Syncfusion Team June 23, 2020 12:04 PM UTC

Hi Jyoti,  

Thank you for contacting Syncfusion support. 

We are unable to reproduce the reported issue with the provided details. Can you please share us the PDF document in which you are facing the issue and the simple sample. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 



JS Jyoti Sharma June 24, 2020 05:49 AM UTC

This is the code from the syncfusion documentation which I used for Pdf Viewer Service and the file is also attached.
        [HttpPost]
        public object Load(Dictionary<string, string> jsonObject)
        {
            PdfRenderer pdfviewer = new PdfRenderer();
            MemoryStream stream = new MemoryStream();
            object jsonResult = new object();
            if (jsonObject != null && jsonObject.ContainsKey("document"))
            {
                if (bool.Parse(jsonObject["isFileName"]))
                {
                    string documentPath = GetDocumentPath(jsonObject["document"]);
                    if (!string.IsNullOrEmpty(documentPath))
                    {
                        byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
                        stream = new MemoryStream(bytes);
                    }
                    else
                    {
                        return(jsonObject["document"] + " is not found");
                    }
                }
                else
                {
                    byte[] bytes = Convert.FromBase64String(jsonObject["document"]);
                    stream = new MemoryStream(bytes);
                }
            }
            jsonResult = pdfviewer.Load(stream, jsonObject);
            return (JsonConvert.SerializeObject(jsonResult));
        }



Attachment: PDF_File_b1ea3823.zip


MS Mohan Selvaraj Syncfusion Team June 26, 2020 02:11 PM UTC

Hi Jyoti, 

We have analyzed the provided PDF documents, In this the provided document contains more text content and images. So it takes some time to render the PDF Pages in our PDF Viewer control since Syncfusion PDF Viewer control is client and server based. We will send the required data from the client side and in server side we will process in our source with the data and return the response data required for rendering the PDF Pages in client side .So it may take some time to render the PDF pages. However we are currently analyzing the way to reduce the size of the data returning from the server side and will update the further details once we analyzed from our end . 

Regards, 
Mohan S 


Loader.
Up arrow icon