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

Display PDF from byte array

3 Answers 325 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 20 Jan 2011, 07:03 PM
I want to show a PDF without saving it to disk on the server.

I call a WCF method and recieve a byte array. I then save the PDF to the IsolatedStorage. But then I cannot display it in the HTMLPlaceHolder.

IsnĀ“t there a way to display a file such as HTML or PDF without saving it on the server?

/R

 

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 25 Jan 2011, 02:29 PM
Hi Raymond,

If you have the byte stream of an HTML page, you can display it in the RadHtmlPlaceholder using the HtmlSource property:
string htmlSource = "";
StreamReader reader = new StreamReader(htmlStream);
String line;
 
while ((line = reader.ReadLine()) != null)
{
    htmlSource += line;
}
 
reader.Close();
htmlPlaceHolder.HtmlSource = htmlSource;

Also, you can use the same approach to display HTML files saved in an isolated storage:
htmlPlaceHolder.HtmlSource = GetContentOfFile("MyTestFile.html");
...
public string GetContentOfFile(string FileName)
{
    string result = "";
    IsolatedStorageFileStream iStream = new IsolatedStorageFileStream(FileName, FileMode.Open, isoStore);
 
    StreamReader reader = new StreamReader(iStream);
    String line;
 
    while ((line = reader.ReadLine()) != null)
    {
        result += line;
    }
 
    reader.Close();
 
    return result;
}

Unfortunately, displaying PDF files in Silverlight is still quite limited. You can use the HtmlPlaceHolder to display them but you will need to store the files on the server.

I hope this information will help you. If you need more, please let us know.

All the best,
Tina Stancheva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
danparker276
Top achievements
Rank 2
answered on 03 Jul 2012, 08:56 PM
PDF streams are binary data, so that wouldn't work.  I don't think there is a way to display a pdf (using the browsers adobe plugin) from a stream without a uri right?  
This below won't work.
string text = Convert.ToBase64String(myPDFStream.ToArray());
htmlPlaceholder1.HtmlSource = text;

It only accepts a string right.  Adding header information isn't going to help.  This can't be done with the silverlight5 webbrowser either I'm guessing.  I guess the best thing to do is stream it from a web service, but that's an extra step if I'm creating the pdf on the silverlight level to take a load off the server.

The telerik silverlight pdf viewer is having problems printing my document, so I'm using the adobe browser plugin for now.
0
Petar Mladenov
Telerik team
answered on 06 Jul 2012, 10:08 AM
Hello danparker276 ,

 Yes you are right, the code you provided won't work. The HtmlPlaceholder cannot accept use such string converted from stream.

Greetings,
Petar Mladenov
the Telerik team

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

Tags
HTMLPlaceHolder
Asked by
Raymond
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
danparker276
Top achievements
Rank 2
Petar Mladenov
Telerik team
Share this question
or