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
close icon

Performance issues with PDF Viewer

Having trouble with performance on the PDF Viewer with a 25mb 400 page document. The pages take way too long to load, I am avoiding using MemoryStream as it loads way too much into Memory.


App: Blazor Server

Storage: Azure Blob


16 Replies

VV Visvesvar Venkatesan Syncfusion Team October 26, 2022 08:36 AM

Hi Garrett,


We thought that the document with 400 pages and 25 MB was hosted on one Azure site and the application was hosted in your local or hosted environment. So when trying to load the document from some other website it takes some time to download the document from the URL.


For example, we try to load the below document with 25 MB directly it took 6-7 seconds locally.

    protected
override
void OnInitialized()

    {

        DocumentPath = "wwwroot/Data/10840.pdf";

    }


But when we try to load it as a URL,  it takes 18 -  20 seconds to load the document. It depends on the downloading speed.


    protected
override
void OnInitialized()

    {

        string Url = https://research.nhm.org/pdfs/10840/10840.pdf;

        System.Net.WebClient webClient = new System.Net.WebClient();

        byte[] byteArray = webClient.DownloadData(Url);

        DocumentPath = "data:application/pdf;base64," + Convert.ToBase64String(byteArray);

    }


Kindly find the sample for it below.


Sample- https://www.syncfusion.com/downloads/support/directtrac/general/ze/server-app-test_(1)376814882.zip



Regards,

Visvesvar K V



GA Garrett November 1, 2022 12:32 PM

Even with 

MaximumReceiveMessageSize = 102400000 the application cannot handle the amount of data sent through the



GA Garrett November 1, 2022 07:22 PM

When I use LoadAsync on PDF Viewer using a stream returned from the Data layer, it is working for large documents, but taking forever to load. 



VV Visvesvar Venkatesan Syncfusion Team November 2, 2022 08:23 AM

Thank you for your update.


As we already stated it will take some time to load the document from some other remote URL and it depends on the network speed. So Kindly provide us with the following details to investigate further on this issue.


1) Kindly share the sample or code snippet in which you replicated the scenario.

2) Also kindly provide us with the time taken to render the document.

3) Kindly provide us with the blob you are using (It should be accessible by us). Provide us with a simple sample.



GA Garrett November 2, 2022 03:03 PM

https://stmunichaindev.blob.core.windows.net/public-container/undefined%20(5).pdf


Here is the large 400 page 25mb pdf


Code snippet is the same as referenced on Syncfusion documentation. I am using Azure managed SignalR though, not standard signalr



GA Garrett November 3, 2022 03:01 AM

public async Task

GetFile(string id, string container) { var client = blobServiceClient.GetBlobContainerClient(container); BlockBlobClient blockBlobClient = client.GetBlockBlobClient(id); var fileContent = (await blockBlobClient.GetPropertiesAsync()).Value; var file = await blockBlobClient.OpenReadAsync(); return file; }

if (file != null)

            {

                await Viewer.LoadAsync(file);

            }



VV Visvesvar Venkatesan Syncfusion Team November 3, 2022 06:58 AM

We have tried with the below sample. On average, It takes 17 to 20 seconds to download the PDF document from the blob.


We have two approaches


DocumentData

Blazor did not show the property change notification When we try to convert the document into a base64 string and update the value to the DocumentData parameter.

 

So we suggest using StateHasChanged() after setting the base64 string to DocumentData parameter to load the document.

    public async void UsingDocumentPath()

    {

        await js.InvokeVoidAsync("console.log", "Start Download..");

        DateTime a = DateTime.Now;

        string Url = https://stmunichaindev.blob.core.windows.net/public-container/undefined%20(5).pdf;

        System.Net.WebClient webClient = new System.Net.WebClient();

        byte[] byteArray = webClient.DownloadData(Url);

        DateTime b = DateTime.Now;

        await js.InvokeVoidAsync("console.log", "Download time : " + (b - a).ToString());

        DocumentData = "data:application/pdf;base64," + Convert.ToBase64String(byteArray);

        StateHasChanged();

    }

 

LoadAsync

When trying to load the document as a memory stream it takes 3 to 4 seconds to load the document once the document has been downloaded from the blob URL.

 

    public async void UsingLoadAsync()

    {

        await js.InvokeVoidAsync("console.log", "Start Download..");

        DateTime a = DateTime.Now;

        string Url = https://stmunichaindev.blob.core.windows.net/public-container/undefined%20(5).pdf;

        System.Net.WebClient webClient = new System.Net.WebClient();

        byte[] byteArray = webClient.DownloadData(Url);

        stream = new MemoryStream(byteArray);

        DateTime b = DateTime.Now;

        await js.InvokeVoidAsync("console.log", "Download time : " + (b - a).ToString());

        await Viewer.LoadAsync(stream);

    }

 


Note: We suggest using LoadAsync API with a memory stream when handling larger-size PDF documents.





GA Garrett November 3, 2022 01:36 PM

Note: We suggest using LoadAsync API with a memory stream when handling larger-size PDF documents.


Original Problem:

The pages take way too long to load, I am avoiding using MemoryStream as it loads way too much into Memory.

Even with MaximumReceiveMessageSize = 102400000 the application cannot handle the amount of data sent through the buffer.


The problem also is the Syncfusion PDF Viewer when loading large document will freeze up the whole page, I am unable to add comments, unable to 




VV Visvesvar Venkatesan Syncfusion Team November 7, 2022 07:09 AM


Kindly find the response.


 

Original Problem:

 

The pages take way too long to load, I am avoiding using MemoryStream as it loads way too much into Memory.

Even with MaximumReceiveMessageSize = 102400000 the application cannot handle the amount of data sent through the buffer.

 

 

As we updated already, we can able to load the document in two ways like DocumentData, and LoadAsync API.

 

when we try to load the document as a base64 string with the DocumentData property, we will convert the base64 into a memory stream internally and we will properly dispose the memory stream object by unloading the component.

 

So you can use the memory stream to load the document instead DocumentData property for larger files.

 

 

The problem also is the Syncfusion PDF Viewer when loading large document will freeze up the whole page, I am unable to add comments, unable to 

 

 

From your comments, we understand that you are not able to add the comments in the document once loaded.

 

This issue causes you have added Commenting as Not allowed . Please check the below screen short.

 

 

 

 

Please find the below links to update the document restrictions summary.

https://www.syncfusion.com/kb/7905/how-to-restrict-printing-and-copying-of-pdf-document-for-security-documents

https://www.syncfusion.com/kb/7905/how-to-restrict-printing-and-copying-of-pdf-document-for-security-documents

https://help.syncfusion.com/file-formats/pdf/working-with-security

 



GA Garrett November 7, 2022 09:46 AM

when we try to load the document as a base64 string with the DocumentData property, we will convert the base64 into a memory stream internally and we will properly dispose the memory stream object by unloading the component.

 

So you can use the memory stream to load the document instead DocumentData property for larger files.


Can you provide a sample on how to do this properly? I am unable to find



GA Garrett November 7, 2022 09:49 AM

{"EventId":1,"LogLevel":"Information","Category":"Microsoft.Azure.SignalR.DefaultServiceEventHandler","Message":"d4a19d94-7829-4903-9495-40eca9bd3e56 recieved service event for ServerConnection(4fkWE0Tscw9jIuOovddVig829b8b1c1) is BufferFull, message is: Buffer for server connection \u00274fkWE0Tscw9jIuOovddVig829b8b1c1\u0027 is full.","State":{"Message":"d4a19d94-7829-4903-9495-40eca9bd3e56 recieved service event for ServerConnection(4fkWE0Tscw9jIuOovddVig829b8b1c1) is BufferFull, message is: Buffer for server connection \u00274fkWE0Tscw9jIuOovddVig829b8b1c1\u0027 is full.","connectionId":"d4a19d94-7829-4903-9495-40eca9bd3e56","objectType":"ServerConnection","objectId":"4fkWE0Tscw9jIuOovddVig829b8b1c1","kind":"BufferFull","message":"Buffer for server connection \u00274fkWE0Tscw9jIuOovddVig829b8b1c1\u0027 is full.","{OriginalFormat}":"{connectionId} recieved service event for {objectType}({objectId}) is {kind}, message is: {message}"}}



GA Garrett November 7, 2022 02:03 PM

Can we please schedule a call?



VV Visvesvar Venkatesan Syncfusion Team November 8, 2022 07:18 AM

We have already provided a code snippet for your requirement on November 3rd itself. Kindly find it again below.


We suspect that JSON you have provided has nothing to do with PDF Viewer related issue.



LoadAsync

When trying to load the document as a memory stream it takes 3 to 4 seconds to load the document once the document has been downloaded from the blob URL.

    public async void UsingLoadAsync()

    {

await js.InvokeVoidAsync("console.log""Start Download..");

DateTime a = DateTime.Now;

string Url = https://stmunichaindev.blob.core.windows.net/public-container/undefined%20(5).pdf;

        System.Net.WebClient webClient = new System.Net.WebClient();

byte[] byteArray = webClient.DownloadData(Url);

        stream = new MemoryStream(byteArray);

DateTime b = DateTime.Now;

await js.InvokeVoidAsync("console.log""Download time : " + (b - a).ToString());

await Viewer.LoadAsync(stream);

    }



Kindly revert to us if you still have any concerns. If your issue still does not get clarified we can have a web meeting to look into the issue.




GA Garrett November 9, 2022 11:51 AM

Hi, it's actually not a problem of downloading the file.


It is that with such a large file, the PDF Viewer will freeze, sometimes will allow annotations, sometimes not allow, not allow clicking on other elements of the page, etc.



GA Garrett November 9, 2022 04:56 PM

Can you open a support ticket in my account so I can send video of the issue



VV Visvesvar Venkatesan Syncfusion Team November 10, 2022 05:28 AM

We have created a ticket for your account. Kindly update that ticket regarding the reported issue.


Loader.
Live Chat Icon For mobile
Up arrow icon