.netprintingreportingactivereports

How to know the print task is aborted using ActiveReport SystemPrinter?


I am completely new to ActiveReport.

I have a legacy VB6 code that uses ActiveReport 2.0. The printing flow is as follows (the code is VB, the initialization of ar is not shown)

Dim ar as DDActiveReports2.ActiveReport

Dim aborted As Boolean
aborted = False
ar.Printer.StartJob("some job")
For i = 0 To ar.Pages.Count - 1
  ar.Printer.StartPage()
  If ar.Printer.Status = DDActiveReports2.JobStatus.ddJSAborted Then
    ar.Printer.AbortJob()
    aborted = True
    Exit For
  End If
  ar.Printer.PrintPage(ar.Pages(i), left, top, width, height)
  ar.Printer.EndPage()
Next
If Not Aborted Then
  ar.Printer.EndJob()
End If

I am trying to migrate it to ActiveReport for .NET. After some research, I find out that the best replacement here is ActiveReports.SystemPrinter. The migrated code could be something like as below (initialization of ar is not shown),

Dim ar As ActiveReports.Document.SectionDocument

Dim aborted As Boolean = False
Dim printer As New ActiveReports.SystemPrinter
printer.StartJob("some job")
For i = 0 To ar.Pages.Count - 1
  printer.StartPage()
  If ??? Then
    printer.AbortJob()
    aborted = True
    Exit For
  End If
  ar.Pages(i).Draw(printer.Graphics, New RectangleF(left, top, width, height))
  printer.EndPage()
Next
If Not Aborted Then
  printer.EndJob()
End If

However, I cannot find printer.Status in as in ActiveReport2, and there is no way to know printing aborted status DDActiveReports2.JobStatus.ddJSAborted.

I am not really too sure what DDActiveReports2.JobStatus.ddJSAborted really is, my guess is the user may cancel the printing in Windows Printing Tasks window. Once this is cancelled, the program will cancel all remaining pages.

However, this seems cannot be done in .NET? Am I missing something?

Please help.

Thanks.


Solution

  • the SectionDocument class in .NET version has PrintAborted event handler. here is a sample of code:

    Imports GrapeCity.ActiveReports

    Imports GrapeCity.ActiveReports.Document

        Dim WithEvents my_document As SectionDocument
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        my_document = New SectionDocument()
        my_document.Load(ms)
        my_document.Print(False)
    End Sub
    
    Private Sub PrintAborted(sender As Object, e As EventArgs) Handles my_document.PrintAborted
        MsgBox("PrintAborted")
    End Sub
    

    please do not forget to add the references in project to GrapeCity.ActiveReports.Extensibility.dll and GrapeCity.ActiveReports.Viewer.Win.dll

    Thanks,