Document is loaded but Print does nothing

3 posts, 1 answers
  1. Jeff
    Jeff avatar
    5 posts
    Member since:
    Jul 2006

    Posted 10 Feb Link to this post

    I am building a WPF form and using Telerik WPF 2017.1.117.  I have a pdf loading fine from an external URL, but when I call the .Print command nothing is spooled and no errors are generated.  After searching as much as I could, I can't find anything that would show why what I have is not working.  Thanks for any help you can provide.

     

    using (WebClient client = new WebClient())
    {
    using (Stream ms = new MemoryStream(client.DownloadData(Properties.Settings.Default.URL + badgeURL)))
    {
    MemoryStream mStream = new MemoryStream();
    mStream.SetLength(ms.Length);
    ms.Read(mStream.GetBuffer(), 0, (int)ms.Length);
    this.radPDF.DocumentSource = new PdfDocumentSource(mStream);
    }
    }

    this.radPDF.Print(new PrintSettings("Document 1", true));

  2. Answer
    Martin
    Admin
    Martin avatar
    1227 posts

    Posted 13 Feb Link to this post

    Hello Jeff,

    When you set the DocumentSource property, the document will be loaded async. This causes the behavior observed on your side. Basically, when the Print() method is called, the document is not loaded.

    To achieve your requirement you can subscribe for the Loaded event of the PdfDocumentSource object and call the Print() method there.
    void pdfDocumentSource_Loaded(object sender, EventArgs e)
    {
        Dispatcher.BeginInvoke(new Action(() =>
        {
            this.radPDF.Print(new PrintSettings("Document 1", true));
        }));
    }
    Note that you will need to delay the printing because the Document property of the PdfViewer is set a bit after the document is loaded. This is why there is a Dispatcher in the code snippet.

    I hope this helps.

    Regards,
    Martin
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Jeff
    Jeff avatar
    5 posts
    Member since:
    Jul 2006

    Posted 13 Feb in reply to Martin Link to this post

    Thank you so much! I was able to figure out that I also needed to add this line to call that and it started working.

    this.radPDF.DocumentSource.Loaded += pdfDocumentSource_Loaded;

     

Back to Top