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

Document is loaded but Print does nothing

2 Answers 106 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 10 Feb 2017, 02:33 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 13 Feb 2017, 11:08 AM
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.
0
Jeff
Top achievements
Rank 1
answered on 13 Feb 2017, 03:06 PM

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;

 

Tags
PDFViewer
Asked by
Jeff
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or