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

Print multiple reports directly to printer from Silverlight

3 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
HDC
Top achievements
Rank 1
HDC asked on 27 May 2011, 06:20 AM
I'm creating an invoicing system that should be able to print multiple invoices without viewing them and with the same printer settings.

To enable this scenario i need to be able to pop up a printer dialog form and then i need to be able to use those setting to print multiple reports directly to the selected printer.

Is this possible with Telerik reporting and if so can somebody direct me to some sample code?


3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 27 May 2011, 10:14 AM
Hi Peter,

Being able to print a report without the viewer is a valid case so we will think about extending the existing functionality to allow this. For the moment the only way to print reports from Silverlight is by using the Silverlight report viewer.
You get the model from the viewer's first child. Here is a sample snippet that illustrates the approach:
Copy Code
Copy Code
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
    }
 
    void button1_Click(object sender, RoutedEventArgs e)
    {
        this.ReportViewer1.PrintReport();
    }
}
 
static class ReportViewerExtensions
{
    public static void PrintReport(this ReportViewer reportViewer)
    {
        var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
        var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
        var printCommand = viewerModel.PrintReportCommand;
        if (printCommand.CanExecute(null))
        {
            printCommand.Execute(null);
        }
    }
}

Hope it helps.

Best wishes,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
ismail
Top achievements
Rank 1
answered on 18 Mar 2012, 02:36 PM
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0); 
dont work. 
VisualTreeHelper.GetChildrenCount(this.ReportViewer1) result is zero.


please help
0
Peter
Telerik team
answered on 21 Mar 2012, 05:06 PM
Hi ismail,

Did you set the ReportViewer.Visibility property to Collapsed? If this is the case have in mind that the control's visual tree is not created in this case. Instead if you want to hide the report viewer you have to set the ReportViewer.Height/Width to 0. Additionally have in mind that the suggested approach will only work for the  true print functionality. Thus our suggestion is to set the ReportViewer.UseNativePrinting to False.

<telerik:ReportViewer Grid.Row="1" x:Name="ReportViewer1"
                      UseNativePrinting="False"
                      Width="0"
                      Height="0"
                      ReportServiceUri="../ReportService.svc"
                      Report="Telerik.Reporting.Examples.CSharp.ReportCatalog, CSharp.ReportLibrary" />
Another approach you can utilize is elaborated in the following forum thread.

Regards,
Peter
the Telerik team
NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Tags
General Discussions
Asked by
HDC
Top achievements
Rank 1
Answers by
Steve
Telerik team
ismail
Top achievements
Rank 1
Peter
Telerik team
Share this question
or