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

Dynamically Load Pdf into PDF Viewer

1 Answer 620 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Goutham
Top achievements
Rank 1
Goutham asked on 15 Jun 2012, 10:59 PM
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
   [Invoke]
        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();


            fs.Close();
        }



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

1 Answer, 1 is accepted

Sort by
0
Kammen
Telerik team
answered on 18 Jun 2012, 12:04 PM
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.

Greetings,
Kammen
the Telerik team

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

Tags
PDFViewer
Asked by
Goutham
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Share this question
or