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

Print from the Silverlight Report Viewer without Viewing the Report

9 Answers 319 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 1
Grant asked on 23 Nov 2010, 03:51 AM
Hi,

Is there a way to print from the 2010 Q3 Silverlight Report Viewer without having to view the report first?


Ta,
Grant.

9 Answers, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 24 Nov 2010, 06:52 PM
Hi Grant,

Currently you can't print the report directly in Silverlight without the report viewer. As a workaround our suggestion is to export the report directly in PDF as elaborated in Exporting Report in Silverlight help article. Once you have the PDF exported you can use Adobe Reader to print the report. Another approach is to hide the Silverlight Report Viewer by setting it's height and width property to 0px, set UseNativePrinting="False". Then you can print the report without showing the reportviewer with the following code:

Copy Code
private void PrintButton1_Click(object sender, RoutedEventArgs e)
{
    var reportViewerModel = ReportViewer1.DataContext as ReportViewerModel;
    if(reportViewerModel.State.Equals("ViewerPageState"))
        reportViewerModel.PrintReportCommand.Execute(null);
}

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Grant
Top achievements
Rank 1
answered on 25 Nov 2010, 09:07 PM
Hi,

Thanks for the reply Steve.

Unfortunately, with UseNativePrinting set to False I get the following message "Printing through the Telerik ReportViewer requires web browser".  Our application will run prodominantly Out of Browser :(

With UseNativePrinting set to True a print confirmation dialog appears ("Document ready.  Continue with Print?").

So at this stage we'll just have to always show the report before the user selects to print - not ideal for use, but hopefully Telerik can include this as a future feature.

Thanks again,
Grant.
0
Steve
Telerik team
answered on 26 Nov 2010, 08:20 AM
Hi Grant,

Unfortunately this behavior of the native Silverlight print cannot be changed. In fact we do not show the "Document ready.  Continue with Print?" dialog out of courtesy, but because Silverlight requires that the print is user initiated and there is even a time frame within which you have to initiate it, otherwise an exception is thrown. You can try printing on your own through the Silverlight API to see this behavior.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Tomas
Top achievements
Rank 1
answered on 11 Jan 2011, 08:36 PM

Hi Steve,

I tried your second suggestion (to hide the reportviewer) but with UseNativePrinting set to True. I'm okay with the "extra" dialog that appears by using Silverlight printing. But I have a problem if I try to print a second time, because then reportViewerModel.State is equal "PrintNoPrintState" and the printcommand won't be executed because of the if clause. By having UseNativePrinting="False" the reportViewerModel's state is always equal to "ViewerPageState" regardless how many times I print.

Any suggestions?

Tomas

0
Steve
Telerik team
answered on 14 Jan 2011, 05:57 PM
Hello Grant,

The provided code snippet is meant to work only with the true PDF print and not with the Silverlight native print. If you want to use it, you can remove the reportViewerModel.State check, which should not cause a problem with the true Print.

Greetings,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Vijetha
Top achievements
Rank 1
answered on 13 Dec 2011, 01:32 PM
Hi,

In simiar way i want to Export the data of  a reportviewer please suggest .


thanks,
Vijetha.k
0
Witold
Top achievements
Rank 1
answered on 09 Apr 2014, 01:08 PM
Hello,

I'm using Telerik Report Silverlight Viewer 2014 Q1 and code above doesn't work because ReportViewer1.DataContext is null.

I have fully working WCF service and I'm able to print/export report from viewer but unable to invoke print command from separate button. Any idea?

Greetings,
Witold.
0
Stef
Telerik team
answered on 11 Apr 2014, 02:06 PM
Hello,

Try getting the ReportViewer from the visual tree as follows:
private void Button_Click(object sender, RoutedEventArgs e)
    {
 
        var layoutRoot = (FrameworkElement)System.Windows.Media.VisualTreeHelper.GetChild(this.ReportViewer1, 0);
        var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);
 
 
        if (reportViewerModel.State.Equals("ViewerPageState"))
            reportViewerModel.PrintReportCommand.Execute(null);
 
    }
Then you need to check for the state of the viewer in order the command to be executed.

I hope this helps you.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Witold
Top achievements
Rank 1
answered on 14 Apr 2014, 07:22 AM
Hi,

this is the solution, thank you.

Greetings,
Witold
Tags
General Discussions
Asked by
Grant
Top achievements
Rank 1
Answers by
Steve
Telerik team
Grant
Top achievements
Rank 1
Tomas
Top achievements
Rank 1
Vijetha
Top achievements
Rank 1
Witold
Top achievements
Rank 1
Stef
Telerik team
Share this question
or