Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
320
print external ".igr"-Report without displaying anything with a WPF application
posted

I want to print a report without any preview or action on the screen (due to automatic printouts without any needed/wanted user actions).

I have an external defined report file (.igr) and an class which implements GetDataSource() to provide the data for the report.

I can display the report using a XamReportViewer.

I tried the following code:

void repPrint_ProcessingCompleted(object sender, Infragistics.Reports.ProcessingCompletedEventArgs e)
{
  XamReportViewer repPrint = sender as XamReportViewer;
  if (repPrint != null)
  { 
    LocalPrintServer localPrtSrv = new LocalPrintServer();
    PrintQueue prtQueue = localPrtSrv.DefaultPrintQueue;
    Infragistics.Controls.Reports.PageSettings curPageSettings = 
      repPrint.GetCurrentPageSettings();
    Infragistics.Controls.Reports.PaperSettings paperSettings =
      new Infragistics.Controls.Reports.PaperSettings(curPageSettings.PaperSize, 
                                        curPageSettings.PageOrientation);
    repPrint.Print(paperSettings, prtQueue, 
                   Infragistics.Controls.Reports.PageRange.All);
  }
}

But this has two problems:
- The report is shown on the screen
- There is an error when calling repPrint.Print() (threading-problem):
Infragistics.Reports.Engine.EngineException: An error occurred while 
      processing the report.
Exception Message:
Der aufrufende Thread kann nicht auf dieses Objekt zugreifen,
    da sich das Objekt im Besitz eines anderen Threads befindet.
Stack Trace:
   bei System.Windows.Threading.Dispatcher.VerifyAccess()
   bei System.Windows.DependencyObject.GetValue(DependencyProperty dp)
   bei System.Windows.VisualStateManager.GetVisualStateGroupsInternal(FrameworkElement obj)
   bei System.Windows.VisualStateManager.GoToStateCommon(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, Boolean useTransitions)
   bei System.Windows.VisualStateManager.GoToState(FrameworkElement control, String stateName, Boolean useTransitions)
   bei Infragistics.Controls.Reports.XamReportViewer.SetVisualState(String state)
   bei Infragistics.Controls.Reports.ViewerStateMachine.ReportPrintServicePrintFinished(Object sender, PrintServiceFinishedEventArgs e)
   bei Infragistics.Controls.Reports.ProcessingSessionStateMachine.ReportPrintServicePrintFinished(Object sender, PrintServiceFinishedEventArgs e)
   bei Infragistics.Controls.Reports.ReportPrintService.RaisePrintFinishedEvent(Exception error)
   bei Infragistics.Controls.Reports.ReportPrintService.PrintHelper(PageSettingsData pageSettingsData, PrintTicket printTicket, PrintQueue printer, PageRange range)
   bei Infragistics.Controls.Reports.ReportPrintService.Print(PageSettingsData pageSettingsData, PaperSettings paperSettings, PrintQueue printer, PageRange range)
   bei Infragistics.Controls.Reports.ProcessingSessionStateMachine.Print(PageSettingsData currentPageSettingsData, PaperSettings paperSettings, PrintQueue printer, PageRange range)
   bei Infragistics.Controls.Reports.ViewerStateMachine.Print(PaperSettings paperSettings, PrintQueue printer, PageRange range)
   bei Infragistics.Controls.Reports.XamReportViewer.Print(PaperSettings paperSettings, PrintQueue printer, PageRange range)
   bei IG_Reporting.MainWindowViewModel.repPrint_ProcessingCompleted(Object sender, ProcessingCompletedEventArgs e) in D:\Projekte(Lokal)\VS2010Prj\IG-Reporting\IG-Reporting\MainWindowViewModel.cs:Zeile 59.


WHAT IS THE CORRECT WAY TO PRINT AN .IPR-REPORT
WITHOUT DISPLAYING ANYTHING???
Parents Reply Children
No Data