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

PdfjsProcessingSettings File from Stream or URL

4 Answers 791 Views
PdfViewer
This is a migrated thread and some comments may be shown as answers.
XicoFininho
Top achievements
Rank 2
XicoFininho asked on 13 May 2020, 02:04 PM

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

Sort by
0
Rumen
Telerik team
answered on 18 May 2020, 12:58 PM

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

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
XicoFininho
Top achievements
Rank 2
answered on 18 May 2020, 01:10 PM

Thank you Rumen.

I should've looked at the rest of the demo! :)

0
XicoFininho
Top achievements
Rank 2
answered on 26 Jun 2020, 07:31 AM

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.

0
Accepted
Peter Milchev
Telerik team
answered on 26 Jun 2020, 08:28 AM

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

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.
Tags
PdfViewer
Asked by
XicoFininho
Top achievements
Rank 2
Answers by
Rumen
Telerik team
XicoFininho
Top achievements
Rank 2
Peter Milchev
Telerik team
Share this question
or