Display PDF from byte array

4 posts, 0 answers
  1. Raymond
    Raymond avatar
    24 posts
    Member since:
    Apr 2009

    Posted 20 Jan 2011 Link to this post

    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?



  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 25 Jan 2011 Link to this post

    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;
    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;
        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>>
  3. DevCraft R3 2016 release webinar banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 03 Jul 2012 Link to this post

    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.
  5. Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 06 Jul 2012 Link to this post

    Hello danparker276 ,

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

    Petar Mladenov
    the Telerik team

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

Back to Top