9 Answers, 1 is accepted
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
Our thoughts here at Progress are with those affected by the outbreak.
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?
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/.
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?
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/.
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!
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/.
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
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/.