Hi,
How can we supply a Strem or external URL in the PdfjsProcessingSettings.File in the code behind?
Thank you.
4 Answers, 1 is accepted
Hi Antonio,
Yes, you can load PDF files from stream by integrating RadPdfViewer with Telerik Document Processing Libraries. A live demo demonstrating such approach is available here:
https://demos.telerik.com/aspnet-ajax/pdfviewer/applicationscenarios/dplintegration/defaultcs.aspx
The Document.pdf is the initial file loaded into the PdfViewer, while the stream-processing logic is assigned to the AsyncUpload's OnFileUploaded event handler. You can find it in the code-behind of the demo:
protected void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
byte[] renderedBytes = null;
string extention = Path.GetExtension(e.File.FileName);
// RadFlow Documents
if (Regex.IsMatch(extention, ".docx|.rtf|.html|.txt"))
{
IFormatProvider<RadFlowDocument> provider = null;
RadFlowDocument document = null;
switch (extention)
{
case ".docx": provider = new DocxFormatProvider(); break;
case ".rtf": provider = new RtfFormatProvider(); break;
case ".html": provider = new HtmlFormatProvider(); break;
case ".txt": provider = new TxtFormatProvider(); break;
default: provider = null; break;
}
document = provider.Import(e.File.InputStream);
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfProvider = new
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
using (MemoryStream ms = new MemoryStream())
{
pdfProvider.Export(document, ms);
renderedBytes = ms.ToArray();
}
}
// Workbook Documents
else if (Regex.IsMatch(extention, ".xlsx|.csv"))
{
IWorkbookFormatProvider provider = null;
Workbook document = null;
switch (extention)
{
case ".xlsx": provider = new XlsxFormatProvider(); break;
case ".csv": provider = new CsvFormatProvider(); break;
default: provider = null; break;
}
document = provider.Import(e.File.InputStream);
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider pdfProvider = new
Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
using (MemoryStream ms = new MemoryStream())
{
pdfProvider.Export(document, ms);
renderedBytes = ms.ToArray();
}
}
RadLabel1.Text = "Displayed Document: <b>" + e.File.FileName + "</b>";
RadPdfViewer1.PdfjsProcessingSettings.FileSettings.Data = Convert.ToBase64String(renderedBytes);
}
Regards,
Rumen
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Thank you Rumen.
I should've looked at the rest of the demo! :)
This does not work for large files, I tried with a 3MB file and get the folowing error:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength
The demo crashes as well.
I've tried to setting the <jsonSerialization maxJsonLength="2147483647"/> in the web.config and it does not work.
Can you please have a look as your demo does not work as well?
Thank you.
Hello XicoFininho,
This web.config setting is applicable only for web service calls while the error you receive is due to the server-side serialization of the PdfViewer settings.
To increase the max JSON length for the PdfViewer Serializer, you can use the MaxSerializerLength property of the PdfViewer and set it to int.MaxValue for example.
Regards,
Peter Milchev
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.