This is a migrated thread and some comments may be shown as answers.

Loading Blob to PdfViewer

9 Answers 1323 Views
PdfViewer
This is a migrated thread and some comments may be shown as answers.
Helen
Top achievements
Rank 1
Helen asked on 13 Apr 2020, 02:23 PM

Hi,

I have pdf files stored as a blob in sql database.  Is it possible to load them to PdfViewer? I found this example but it's for MVC.  Do you have an example for webform?

 

 

Thank you,

Helen

 

 

 

9 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 15 Apr 2020, 10:44 AM

Hi Helen,

Thank you for your question!

What you can do is to load the PDF content from the database as a byte array into the PdfViewer as it is shown in the following demo:

Convert, View and Download Different Formats, e.g.

RadPdfViewer1.PdfjsProcessingSettings.FileSettings.Data = Convert.ToBase64String(renderedBytes);

I hope that this will help you achieve your scenario.

Regards,
Rumen
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
ANTONIO
Top achievements
Rank 1
answered on 28 Oct 2020, 01:07 PM

Hi Rumen,

 

This method isn't working for "large" pdf files (with more than 4mb).

 

I've tried to increase the RadPdfViewer1.MaxSerializerLength = int.MaxValue; with no luck.

 

Any suggestions?

0
Rumen
Telerik team
answered on 28 Oct 2020, 01:41 PM

Hi Antonio,

Can you please open the web.config file and set the maxRequestLength and maxJsonLength properties to bigger values:

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="2147483640"/>
    </system.web>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="2147483640"/>
            </webServices>
        </scripting>
    </system.web.extensions>
</configuration> 

 

Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
ANTONIO
Top achievements
Rank 1
answered on 29 Oct 2020, 11:12 AM

Hi Rumen,

Thanks for the quick response!

I've tried your suggestion and it didn't work. I'm using 2020 R2 SP1.

The strange thing is that the error references the property that you suggested to set on web.config.

The error that I receive on the browser is:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
    at Function.Error.create (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:4457)
    at Sys.WebForms.PageRequestManager._createPageRequestManagerServerError (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:118177)
    at Sys.WebForms.PageRequestManager._parseDelta (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:135899)
    at Sys.WebForms.PageRequestManager._onFormSubmitCompleted (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:131983)
    at Array.<anonymous> (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:2148)
    at http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:50368
    at Sys.Net.WebRequest.completed (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:86971)
    at XMLHttpRequest._onReadyStateChange (http://localhost:44375/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81:1:81635)

The file size was 8MB.

Any other suggestion?

0
Rumen
Telerik team
answered on 29 Oct 2020, 02:03 PM

Hi Antonio,

You most likely hit this error because of the MaxSerializerLength setting of RadPdfViewer.

We have such code in the demo, to prevent the upload of very big files:

protected void Page_Load(object sender, EventArgs e)
        {
            int maxSize = 10 * 1024 * 1024; // 10MB
 
            RadAsyncUpload1.MaxFileSize = maxSize;
            RadPdfViewer1.MaxSerializerLength = maxSize;
        }

 

MaxSerializerLength Int32
Specifies the maximum length of accepted JSON strings. Default value is 2 * 1024 * 1024 (2MB=2097152)

Please increase the value of the MaxSerializerLength property to solve the issue.

 

Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
ANTONIO
Top achievements
Rank 1
answered on 03 Nov 2020, 07:58 PM

Hi Rumen!

Thanks again for the quick response!

I was on holiday and only able to test today!

protected void Page_Load(object sender, EventArgs e)
        {
            int maxSize = 10 * 1024 * 1024; // 10MB

            RadAsyncUpload1.MaxFileSize = maxSize;
            RadPdfViewer1.MaxSerializerLength = maxSize;
        }

I already had this code on my page. 

The site is a webforms with master page. I've tried both suggestions with no luck.

 

If I open the same pdf file using the open button on the pdf viewer it shows on the page, but if a load it by code 

RadPdfViewer1.PdfjsProcessingSettings.FileSettings.Data = Convert.ToBase64String(renderedBytes); it give the serialization error. 

 

Notice that i dont get any exception on the visual studio, the pdf simply don't show on the pdf viewer. The error is only show on the developer tools of chrome.

Any other suggestion? 

Thank you again!

Best regards!

0
Rumen
Telerik team
answered on 04 Nov 2020, 06:52 AM

Hi Antonio,

Can you please modify the following code:

protected void Page_Load(object sender, EventArgs e)
{
            int maxSize = 10 * 1024 * 1024; // 10MB

            RadAsyncUpload1.MaxFileSize = maxSize;
            RadPdfViewer1.MaxSerializerLength = maxSize;
}

to

protected void Page_Load(object sender, EventArgs e)
{
            int maxSize = int.MaxValue; //2048MB=2147483647

            RadAsyncUpload1.MaxFileSize = maxSize;
            RadPdfViewer1.MaxSerializerLength = maxSize;
}

 

Best Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
ANTONIO
Top achievements
Rank 1
answered on 04 Nov 2020, 11:18 AM

Thank you Rumen, 

The problem was that I was setting  the MaxSerializerLength after  if (IsPostBack) return;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;

            RadPdfViewer1.MaxSerializerLength = int.MaxValue;

            RadPdfViewer1.EnableAjaxSkinRendering = true;
            RadGrid1.Visible = false;

            RadGrid1.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.TopAndBottom;
            RadGrid1.ExportSettings.Pdf.ContentFilter = GridPdfFilter.NoFilter;
        }

Changing to 

        protected void Page_Load(object sender, EventArgs e)
        {
            RadPdfViewer1.MaxSerializerLength = int.MaxValue;

            if (IsPostBack) return;

            
            RadPdfViewer1.EnableAjaxSkinRendering = true;

            RadGrid1.Visible = false;

            RadGrid1.ExportSettings.Pdf.BorderType = GridPdfSettings.GridPdfBorderType.TopAndBottom;
            RadGrid1.ExportSettings.Pdf.ContentFilter = GridPdfFilter.NoFilter;
        }

 

Did the trick.

 

Thank You Again!!

Best Regards!

Antonio

0
Rumen
Telerik team
answered on 04 Nov 2020, 11:39 AM

You are welcome! I am glad that everything is fine now!

 

Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PdfViewer
Asked by
Helen
Top achievements
Rank 1
Answers by
Rumen
Telerik team
ANTONIO
Top achievements
Rank 1
Share this question
or