Dynamically Load Pdf into PDF Viewer

2 posts, 0 answers
  1. Goutham
    Goutham avatar
    1 posts
    Member since:
    Jun 2012

    Posted 15 Jun 2012 Link to this post

    i am generating an SSRS report into PDF dynamically and i need to show it in the PDF viewer. 
    In the Examples, it is shown that we need to store the PDF in the Application
     and give the document source in the xaml or in .cs file.
    I want to give the PDF url directly .. can you show me how to do that.. 

    So i store the empty pdf file in my Application. I override the empty file with the dynamically generated PDF file.
    Since the function is executed Async.. the old empty file is binded to the Pdfviewer (since the new file is still generating...)
    Here is the code..

                string baseUrl = "http://localserver/ReportServer?&rs:Command=Render&rs:ClearSession=true&rs:Format=PDF"; (its not correct url) 
               string path = @"C:\Users\grcha\Desktop\06-07\Example\l";
                DomainContext pdc = new DomainContext();
                pdc.SaveReportToPdf(baseUrl, path, (operation =>
                pdfViewer.DocumentSource = new PdfDocumentSource(new System.Uri("/Example;component/Report1.pdf", System.UriKind.Relative));                var ids = operation.Value; }), null);

    --- Method in Domain Service
            public void SaveReportToPdf(String baseUrl, String path)
                var req = (HttpWebRequest)WebRequest.Create(baseUrl);

                req.Credentials = CredentialCache.DefaultCredentials;

                req.Method = "GET";

                string reportPath = Path.Combine(path, "Report1.pdf");
                var objResponse = req.GetResponse();

                var fs = new FileStream(reportPath, FileMode.Create);

                var stream = objResponse.GetResponseStream();

                var buf = new byte[1024];

                if (stream != null)
                    var len = stream.Read(buf, 0, 1024);

                    while (len > 0)

                        fs.Write(buf, 0, len);

                        len = stream.Read(buf, 0, 1024);


                if (stream != null) stream.Close();


    can you show me how to do using streams or any other way... 
    Thank you

  2. Kammen
    Kammen avatar
    312 posts

    Posted 18 Jun 2012 Link to this post

    Hi Goutham,

    I am not sure what exactly you are trying to ahieve, but in this article you can find the different ways to load a pdf file in RadPdfViewer. I think that the best way for you is using a PDF stream that contains the report  file, and using the PdfDocumentSource constructor which takes a Stream as an argument.

    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top