none
Displaying A PDF Document Inside A Silverlight UserControl

    Question

  • Hello Everyone,

              I am working on a project in Silverlight 2.0. I need to display a PDF document in a Silverlight Usercontrol. How can I do that?Please help! Thanks in advance.

    Reny Mathew

    Monday, April 28, 2008 1:43 PM

Answers

  • Same as you use IFrame in any HTML page. Set style.position = "absolute" and position it over the Silverlight control. It won't be inside a Silverlight control but on top of it.

    You can put a IFrame tag on your TextPage.HTML/ASPX page.

    <IFRAme id="MyIFrame" style="position:absolute; width:someWidth; height:someHeight; visibility:hidden" /> 

     

    From your silverlight code you can access to the IFrame and set property:

                HtmlElement m = HtmlPage.Document.GetElementById("MyIFrame");          
                if (m != null)
                {

                    m.SetAttribute("src", "URL of your pdf")
                    m.SetStyleAttribute("left", x);
                    m.SetStyleAttribute("top", y);
                    m.SetStyleAttribute("visibility", "visible");
                }

     

    Wednesday, April 30, 2008 9:56 AM

All replies

  • I do believe that you're going to have to float an iframe on top of your SL app to achieve this.  AFAIK there is no way to instantiate another browser plugin in SL.

    Monday, April 28, 2008 4:14 PM
  • Thanks Chandler for your response.  How can I make an IFrame float inside a Silverlight User Control. I am totally new to this technology. Can you give me some examples?

    Thanks, Reny.

    Wednesday, April 30, 2008 9:38 AM
  • Same as you use IFrame in any HTML page. Set style.position = "absolute" and position it over the Silverlight control. It won't be inside a Silverlight control but on top of it.

    You can put a IFrame tag on your TextPage.HTML/ASPX page.

    <IFRAme id="MyIFrame" style="position:absolute; width:someWidth; height:someHeight; visibility:hidden" /> 

     

    From your silverlight code you can access to the IFrame and set property:

                HtmlElement m = HtmlPage.Document.GetElementById("MyIFrame");          
                if (m != null)
                {

                    m.SetAttribute("src", "URL of your pdf")
                    m.SetStyleAttribute("left", x);
                    m.SetStyleAttribute("top", y);
                    m.SetStyleAttribute("visibility", "visible");
                }

     

    Wednesday, April 30, 2008 9:56 AM
  • I do this exact operation with another activeX control. The one thing that took me a bit to figure out was, the control itself has an IsWindowless parameter that had to be set to -1, in this case, to allow the control to float over the silverlight control.

    For displaying a pdf, I actually pop open another window with a content-disposition header to automatically download.  I may try this method for displaying though. 

    Will this method allow the user to print the pdf individually?

    Wednesday, April 30, 2008 10:53 AM
  •  Yes, I forgot to mention you need to set silverlight object windowless parameter to true in order to have HTML element float over the silverlight control.

    <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%"> 

    <param name="windowless" value="true" /> 

    <param ../> 

    I never tested print function for IFrame. But I have a EarthLive Map been put into a floating DIV. When I click the browser print, it will only print the Map. But the controls inside Silverlight control are not shown .

     


    Wednesday, April 30, 2008 1:54 PM
  • Excellent, I will have to try this out.  Adding it to my ever growing list of improvements for v2 of our website.

    Thanks!

    Wednesday, April 30, 2008 2:26 PM
  • Excellent, I will have to try this out.  Adding it to my ever growing list of improvements for v2 of our website.

    Thanks!

     

    I should mention I'm not sure the printout is what you want. In my case, the Map is not full screen. So when print, even it's the only thing shown in the printout, but it still not full page. The rest of the area is just blank.

    Wednesday, April 30, 2008 2:49 PM
  • Thanks guys, I got it working :)

    Thursday, May 01, 2008 1:28 PM
  • CAn you send me sample codes. arif.mahmood@sungard.com

    Tuesday, December 02, 2008 6:13 PM
  • Hello Reny,

     I have been working on same issue. Can you please send code for this

     Thanks in Advance

    Regards 

    Shilpi

    Wednesday, April 15, 2009 11:44 PM
  • Hello Reny, I have been working on same issue. Can you please send code for this Thanks in Advance Regards Shilpi
    Wednesday, April 15, 2009 11:46 PM
  • If you want to place it comfortably and properly into your Silverlight's page layout (i.e. resize it etc.), then there's a free HtmlHost control for Silverlight at

     

    http://www.divelements.co.uk/silverlight/tools.aspx

     

    with which you can load Html or anything the browser can display, i.e. also PDFs if Adobe's plugin installed. It of course also works with an iframe underneath but takes care of many quirks that come along with it and I have struggled with myself.

    Thursday, April 16, 2009 6:34 AM
  • Thanks guys, I got it working :)

    Hey, i also doing something that need to float a html/aspx page over a silverlight control. can u send me your code? thanks
    Thursday, April 23, 2009 4:14 AM
  •  If you or your company can afford:

    http://www.amyuni.com/silverlight/article.php

    Above link has DLL that will enable your Silverlight application to open pdf

    right in your Silverlight app.

    Thursday, April 23, 2009 6:00 AM
  •  hello dude,

    the iframe works fine on http websites.

    but as soon as you switch to an https website other page disappears and only the page in iframe is displayed.

    can you please help me with this dude!!!

    Tuesday, November 03, 2009 3:10 AM
  •  hey renny

               How u got pdf document inside silverlight user control... im new to this silveright 4.. pls give me more details... :) p.rajbarath@gmail.com

    Thursday, December 09, 2010 12:05 AM
  •  

    PDFTron SilverDox will allow you to view and markup you PDFs in Silverlight 4+:

    http://www.pdftron.com/silverdox/samplecode.html

    Thursday, February 03, 2011 6:03 PM
  • hi

    i have one problem regarding your post , i have implemented and it is working files on my local pc but when i deploy with same application on localhost then it is given me error "

    HTTP Error 404.0 - Not Found

    The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    Module IIS Web Core
    Notification MapRequestHandler
    Handler StaticFile
    Error Code 0x80070002
    Requested URL http://localhost:80/UploadedFiles/00A00A/CHATABBA193309251/DEMOGRAPHIC/04 User Profile.pdf
    Physical Path C:\inetpub\wwwroot\UploadedFiles\00A00A\CHATABBA193309251\DEMOGRAPHIC\04 User Profile.pdf
    Logon Method Anonymous
    Logon User Anonymous

    "

    so can you pls gide me what can i do to solve this error .

    thanks

    Nilesh Sathvara

    Wednesday, May 02, 2012 7:07 AM