Print from the Silverlight Report Viewer without Viewing the Report

10 posts, 1 answers
  1. Grant
    Grant avatar
    3 posts
    Member since:
    Oct 2006

    Posted 22 Nov 2010 Link to this post

    Hi,

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


    Ta,
    Grant.
  2. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 24 Nov 2010 Link to this post

    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.
  3. DevCraft banner
  4. Grant
    Grant avatar
    3 posts
    Member since:
    Oct 2006

    Posted 25 Nov 2010 Link to this post

    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.
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 26 Nov 2010 Link to this post

    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.
  6. Tomas
    Tomas avatar
    92 posts
    Member since:
    Jun 2010

    Posted 11 Jan 2011 Link to this post

    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

  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Jan 2011 Link to this post

    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.
  8. Vijetha
    Vijetha avatar
    9 posts
    Member since:
    Jul 2011

    Posted 13 Dec 2011 Link to this post

    Hi,

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


    thanks,
    Vijetha.k
  9. Witold
    Witold avatar
    2 posts
    Member since:
    Jan 2014

    Posted 09 Apr 2014 Link to this post

    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.
  10. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 11 Apr 2014 Link to this post

    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.

     
  11. Witold
    Witold avatar
    2 posts
    Member since:
    Jan 2014

    Posted 14 Apr 2014 in reply to Stef Link to this post

    Hi,

    this is the solution, thank you.

    Greetings,
    Witold
Back to Top
DevCraft banner