Load from stream?

32 posts, 0 answers
  1. Bryce
    Bryce avatar
    32 posts
    Member since:
    Aug 2010

    Posted 17 Nov 2011 Link to this post

    Any example on how I can get this control to load from a memorystream containing the PDF?

    Edit: Sorry I figured this out on my own. 

    PdfDocumentSource

    This seems very very slow though.  After I hand off the PdfDcoumentSource it shows "loading" for a very long time before rendering the document.

  2. Elke.Eichelhard
    Elke.Eichelhard avatar
    2 posts
    Member since:
    May 2011

    Posted 18 Nov 2011 Link to this post

    Hello Bryce,

    congratulations on figuring that issue out!
    I was`t able to do this.

    Could you please advice me with some example code?

    Thank you very much.
  3. DevCraft banner
  4. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 21 Nov 2011 Link to this post

    Hi Elke.Eichelhard, Bryce,

    Thank you for your interest in RadPDFViewer.
    There are two ways to open a PDF file in the control.  You need to use PdfDocumentSource class, which provides two options to load a file:

    1.     Load a PDF file from stream:

    Stream str = App.GetResourceStream(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative)).Stream;

    this.pdfViewer.DocumentSource = newPdfDocumentSource(str);

    2.     Load a PDF file from Uri:

    this.pdfViewer.DocumentSource = newPdfDocumentSource(newSystem.Uri("DocumentSource;component/Sample.pdf", System.UriKind.Relative));


     We are working on the documentation of the control as we speak and it should be available soon. In the meantime, do not hesitate to contact us if any other questions arise.

    As for the performance issue when loading larger documents, this is due to the fact that the pages are shown only after the whole document is loaded. We have scheduled an optimization which will show the pages one by one when they are parsed and that will resolve the problem.

    Best wishes,
    Kammen
    the Telerik team

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

  5. Wei
    Wei avatar
    3 posts
    Member since:
    Nov 2011

    Posted 22 Nov 2011 Link to this post

    The pdf file needs to be loaded from local resource?
  6. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 22 Nov 2011 Link to this post

    Hello Wei,

    In Kammen's examples, the file is added as a resource in the Silverlight project, but that is not a requirement. One option is to use the OpenFileDialog as done in the FirstLook online demo

    You can just as well load files that are not on the client machine. For example, if you embed a Sample.pdf file in the Web project, you can load it like this:

    <controls:RadPdfViewer x:Name="pdfViewer" Grid.Row="1" DocumentSource="/Sample.pdf" />

    PDF files can be opened as long as you can obtain a stream with their content. Note that due to Silverlight’s security policy, only files from a domain with permissive cross-domain policy can be loaded.

    Best wishes,
    Iva Toteva
    the Telerik team

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

  7. Wei
    Wei avatar
    3 posts
    Member since:
    Nov 2011

    Posted 22 Nov 2011 Link to this post

    I solve it. Thank you!
  8. Wei
    Wei avatar
    3 posts
    Member since:
    Nov 2011

    Posted 22 Nov 2011 Link to this post

    Hi,

    I have a file that is generated in runtime with WCF async call. It is located in Silverlightapp.web folder and file name is generated in the runtime. How to write the DocuementSource and display it in browser?
  9. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 24 Nov 2011 Link to this post

    Hi Wei,

    You can create new PdfDocumentSource passing your file as stream. The only thing you need to do is get your file as a Stream and set the DocumentSource property of the viewer like this:
    this.pdfViewer.DocumentSource = new PdfDocumentSource(FileAsStream);

    Regards,
    Kammen
    the Telerik team

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

  10. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 29 Nov 2011 Link to this post

    I have my PDF in my ClientBin, build action set as content, copy Always

    when I do this the DocumentSource is null:

    System.Uri path = new System.Uri("/testingPDF.pdf", System.UriKind.RelativeOrAbsolute);            
    this.pdfViewer.DocumentSource = new PdfDocumentSource(path);

    Is there something I'm missing? Build action set wrong?
    I also can't get local PDF's to view using the open dialog...
  11. Nikituki
    Nikituki avatar
    34 posts
    Member since:
    Nov 2011

    Posted 30 Nov 2011 Link to this post

    Hello,
    I'am trying to load PDF document to RadPdfViewer.
    var a = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(theMemStream);
    var b = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(new Uri(path, UriKind.Relative));
    Both times document == null.
    What am I doing wrong?

    P.S. Sorry for my bad English
  12. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 30 Nov 2011 Link to this post

    Hello guys, 

    @ jen b 

    If you want to load PDF file located in ClientBin directory, you should try to use code similar to the following:

    this.viewer.DocumentSource = new PdfDocumentSource(new Uri("/ClientBin/Sample.pdf", UriKind.Relative));




    @ Nikituki Nikituki 

    The PdfDocumentSource is loading the document asynchronously. That is why the Document property is null at the time you try to get it. You should use the Loaded event or the PdfDocumentSource object obtain the loaded document.


    Best wishes,
    Kammen
    the Telerik team

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

  13. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 30 Nov 2011 Link to this post

    Thanks for the reply,

    usualy you don't need to include /ClientBin to the path when its relative (since it should be relative to the .xap IN the ClientBin), but I tried that anyways, waited for it to load asynchronously and finally the source is not null!  A step in the right direction, thanks!

    However after setting it to the viewer's DocumentSource, the viewer is still not displaying anything.

    Any more ideas?
  14. Nikituki
    Nikituki avatar
    34 posts
    Member since:
    Nov 2011

    Posted 01 Dec 2011 Link to this post

    @Kammen
    Ok, I'am trying to do this
    var a = new Telerik.Windows.Documents.Fixed.PdfDocumentSource(theMemStream);
    a.Loaded += new EventHandler(a_Loaded);
          
     
    void a_Loaded(object sender, EventArgs e)
    {
         pdfViewer.DocumentSource = (Telerik.Windows.Documents.Fixed.PdfDocumentSource)sender;
    }
    In this case:
    sender.Document == null
    and "System.UnauthorizedAccessException: Invalid cross-thread access error"  occurs
  15. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 02 Dec 2011 Link to this post

    Hi Jen, Nikituki,
    Do you have the same problem when you load your PDF file from open file dialog of the RadPdfViewer?

    @Nikituki Nikituki
    Actually RadPdfViewer will handle the asynchronous loading of the document, so all you need to do is to set PdfViewer.DocumentSource property, as described here.

    All the best,
    Kammen
    the Telerik team

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

  16. jen
    jen avatar
    63 posts
    Member since:
    Jun 2009

    Posted 02 Dec 2011 Link to this post

    Kammen,
    yes, no matter what I've tried, I have not yet managed to see ANY pdf in this viewer
  17. Boby
    Admin
    Boby avatar
    595 posts

    Posted 02 Dec 2011 Link to this post

    Hello Jen,
    Could you please open a support ticket and send us attached some of the problematic PDF documents, so we can investigate the issue further?

    Kind regards,
    Boby
    the Telerik team

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

  18. S W
    S W avatar
    7 posts
    Member since:
    May 2010

    Posted 20 Dec 2011 Link to this post

    It simply does not work for our situation.  We are feeding the RadPdfViewer with MemoryStream, which contains one PDF created by Telerik Report.  Any body can help?
    Thanks!
  19. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 21 Dec 2011 Link to this post

    Hi S W,

    We are happy to announce that we just rolled out a new version (Q3 SP1) of our tools with a lot of enhancements of PDFViewer including issues related to loading documents generated by Telerik Reporting. If the document in question still does not work, please save a stream you are generating as a file and send it to us in a support ticket to investigate the issue further.


    All the best,
    Kammen
    the Telerik team

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

  20. Alex
    Alex avatar
    1 posts
    Member since:
    Dec 2011

    Posted 21 Dec 2011 Link to this post

    hi kammen,

    I am using the trial version RadPdfViewer control, when loading the PDF is destroyed appears strange characters instead of the original content and in some cases does not support pdf of 8, 10 14 MB
  21. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 22 Dec 2011 Link to this post

    Hello,

    It would be great if you open a support ticket and send some PDF files that are not displayed well. In this way, we would be able to look into the import and make the appropriate fixes.


    Greetings,
    Kammen
    the Telerik team

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

  22. Nikituki
    Nikituki avatar
    34 posts
    Member since:
    Nov 2011

    Posted 23 Dec 2011 Link to this post

    Hi,

    I'm attached 2 files.
    First - pdf document in Adobe Reader, Second - in Telerik PdfViewer.
    See the difference? =)
  23. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 23 Dec 2011 Link to this post

    Hello Nikituki,

    RadPdfViewer is in beta stage and it is normal that there are some issues. We are constantly working on extending the supported features. With every release RadPdfViewer will be able to display the documents better than before.
    What you can do in order to help us improve the control is to upload the pdf files instead of screenshots of the result, so that we can look into the content and track down the particular cause of the problem. You can either open a support ticket and attach the files there or upload them somewhere else and post a link in the forums.

    Greetings,
    Kammen
    the Telerik team

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

  24. Jane
    Jane avatar
    3 posts
    Member since:
    Mar 2010

    Posted 03 Jan 2012 Link to this post

    I tried to display pdf file, load from memorystream. I upgrade telerik controls to 2011Q3 sp1. I still can not get pdf file displayed. Can you provide a example how to do it? Thank you for your help!

    This is what I did:
    PreviewReportWindow is a childwindow, which has

     

    <

     

     

    telerik:RadPdfViewer x:Name="pdfViewer"></telerik:RadPdfViewer>

     

     

     

     


    in code behind

     

     

     

    MemoryStream objfileStream;

     

     

     

    public

     

     

    PreviewReportWindow(byte[] pdffilebyte)

     

    {

    InitializeComponent();

    objfileStream =

     

    new MemoryStream(pdffilebyte, true);

     

    objfileStream.Write(pdffilebyte, 0, pdffilebyte.Length);

    this

     

     

    .pdfViewer.DocumentSource = new PdfDocumentSource(objfileStream);

     

    }

    I also tried to put the pdf file in \clientbin of  .web project, or in client project. both cases works,  displayed the pdf file. I can open the pdf file from open file dialogue of pdfviewer.

  25. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 04 Jan 2012 Link to this post

    Hi Jane,

    We could not managed to reproduce the problem. This code snippet should do the trick.

    MemoryStream ms = new MemoryStream(bytes);
    this.pdfViewer.DocumentSource = new PdfDocumentSource(ms);

    If you still face problems with the PdfDocumentSource, please provide us a demo application to further investigate where the problem is.

    Greetings,

    Kammen
    the Telerik team

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

  26. Jane
    Jane avatar
    3 posts
    Member since:
    Mar 2010

    Posted 05 Jan 2012 Link to this post

    Thank you! I tried to load several pdf files. some files works, but some files cannot been displayed in pdfviewer control.
    I switched to save pdf files on the server and  display pdf file in a radhtmlplaceholder,  put the radhtmlplaceholder in a Radwindow.
    The only issue I have now is that when I minimize the radwindow(with pdf file), and then maximize the radwindow, the pdf file disappeared. I am not sure how to disable the minimize function of the Radwindow. Can you help me?
  27. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 10 Jan 2012 Link to this post

    Hello Jane,

    In order to disable the minimize option you need to set the ResizeMode property of the RadWidnow to NoResize. This will disable the sizing of the RadWindow.
    However, if you only want to remove the minimize button, then you need to edit the template of the RadWindow. You can do that very easy with Expression Blend. Just drop a RadWindow on the design surface, right-click it and choose from the menu Edit Template->Edit a Copy. Then Blend will generate all the needed resources. Find the button with x:Name PART_MinimizeButton and set its Visibility property to Collapsed. Then apply the style to the RadWindow as explained in this help article.

    Hope this helps.

    Regards,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  28. bhargav
    bhargav avatar
    5 posts
    Member since:
    Jan 2011

    Posted 30 Mar 2012 Link to this post

    Hi,

    I am trying to load a PDF document into the PDF viewer. THe document is stored in database as a byte array and on retrieval i am converting this bytearray to a stream and displaying it using the following code:
    byte[] byteArrayPdf=(m_ObjDomainContextFlightQuotation.Get_PDF_By_ID_Results.ToList())[this.radGridHistoryList.Items.IndexOf(this.radGridHistoryList.SelectedItem)].Detail;
               Stream s= new MemoryStream(byteArrayPdf);
               radPDFViewer.DocumentSource = new PdfDocumentSource(s);

    But, The PDF file does not show up on my page at all. THe document property of the document source is always null.
    From above discussion, i gather that document can be null if the file is corrupted, but the same byte array when written on an aspx page,like below, works fine an hence i dont think the pdf file is corrupt.
    Response.BinaryWrite(byteArray);

    Please provide me with a solution to this issue?

    Note: I am using the 2012.1.221.1050 version of telerik controls for silverlight.
  29. Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 04 Apr 2012 Link to this post

    Hi Bhargav,
    We will need a little more information to understand the problem and manage to help you.
    Have you tried saving the byte array to a file and then opening it in the viewer using the OpenFileDialog (or directly in our online demo). If the file can be opened successfully, then maybe the problem is somewhere in your application. In that case a sample project that shows the problem (attached to a support ticket) will help us to investigate what is wrong.
    In case the PDF file cannot be opened even with the online demo, we would appreciate it if you send us the file itself so that we can inspect it.

    Kind regards,
    Kammen
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  30. P
    P avatar
    1 posts
    Member since:
    Jul 2011

    Posted 10 Apr 2012 Link to this post

    Migrating to Q1 2012 sp of Dlls solved my issue
  31. Sasan
    Sasan avatar
    1 posts
    Member since:
    May 2012

    Posted 06 May 2012 Link to this post

    What is the xaml code to load from stream?
    What should I do if I want to not to set the build action to resource?
Back to Top
DevCraft banner