private void PrintProgress(object printHelper, gsPrintEventArgs Information) { switch (Information.Status) { case PrintStatus_t.PRINT_ERROR: case PrintStatus_t.PRINT_CANCELLED: case PrintStatus_t.PRINT_READY: case PrintStatus_t.PRINT_DONE: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { if (File.Exists(Information.FileName)) { DeleteTempFile(Information.FileName); } System.Windows.Application.Current.Shutdown(); })); break; case PrintStatus_t.PRINT_BUSY: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { m_printstatus.xaml_PrintProgress.Value = 100.0 * (double)(Information.Page - Information.PageStart) / (double)Information.NumPages; if (Information.Page == Information.NumPages) { m_printstatus.xaml_PrintProgress.Visibility = System.Windows.Visibility.Collapsed; } })); break; } }
/* Done */ private void AsyncCompleted(object sender, WritingCompletedEventArgs e) { PrintStatus_t status; if (e.Cancelled) { status = PrintStatus_t.PRINT_CANCELLED; } else if (e.Error != null) { status = PrintStatus_t.PRINT_ERROR; } else { status = PrintStatus_t.PRINT_READY; } if (PrintUpdate != null) { gsPrintEventArgs info = new gsPrintEventArgs(status, true, 0, this.m_first_page, this.m_num_pages, this.m_filename); PrintUpdate(this, info); } m_busy = false; }
public void Done() { gsPrintEventArgs info = new gsPrintEventArgs(PrintStatus_t.PRINT_DONE, true, 0, 0, 0, this.m_filename); PrintUpdate(this, info); m_busy = false; }
/* Do this update with each fixed document (page) that is handled */ private void AsyncProgress(object sender, WritingProgressChangedEventArgs e) { if (PrintUpdate != null) { gsPrintEventArgs info = new gsPrintEventArgs(PrintStatus_t.PRINT_BUSY, false, e.Number, this.m_first_page, this.m_num_pages, this.m_filename); PrintUpdate(this, info); } }
private void PrintProgress(object printHelper, gsPrintEventArgs Information) { switch (Information.Status) { case PrintStatus_t.PRINT_ERROR: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { ShowMessage(NotifyType_t.MESS_ERROR, "Printer Driver Error"); m_printstatus.xaml_PrintProgress.Visibility = System.Windows.Visibility.Collapsed; m_viewer_state = ViewerState_t.DOC_OPEN; this.Close(); })); break; case PrintStatus_t.PRINT_CANCELLED: case PrintStatus_t.PRINT_READY: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { m_printstatus.xaml_PrintProgress.Visibility = System.Windows.Visibility.Collapsed; m_viewer_state = ViewerState_t.DOC_OPEN; this.Close(); })); break; case PrintStatus_t.PRINT_DONE: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { m_printstatus.xaml_PrintProgress.Visibility = System.Windows.Visibility.Collapsed; DeleteTempFile(Information.FileName); m_viewer_state = ViewerState_t.DOC_OPEN; this.Close(); })); break; case PrintStatus_t.PRINT_BUSY: System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { m_printstatus.xaml_PrintProgress.Value = 100.0 * (double)(Information.Page - Information.PageStart) / (double)Information.NumPages; if (Information.Page == Information.NumPages) { m_printstatus.xaml_PrintProgress.Visibility = System.Windows.Visibility.Collapsed; } })); break; } }
/* Send it */ private void PrintPages(XpsDocumentWriter xpsdw, FixedDocument fixdoc, bool print_all, int from, int to, PrintTicket Ticket) { m_docWriter = xpsdw; xpsdw.WritingCompleted += new WritingCompletedEventHandler(AsyncCompleted); xpsdw.WritingProgressChanged += new WritingProgressChangedEventHandler(AsyncProgress); DocumentPaginator paginator = fixdoc.DocumentPaginator; try { if (print_all) { m_first_page = 1; m_num_pages = paginator.PageCount; xpsdw.Write(paginator, Ticket); } else { /* Create an override paginator to pick only the pages we want */ GSDocumentPaginator gspaginator = new GSDocumentPaginator(paginator, from, to); m_first_page = from; m_num_pages = paginator.PageCount; xpsdw.Write(gspaginator, Ticket); } } catch (Exception) { /* Something went wrong with this particular print driver * simply notify the user and clean up everything */ gsPrintEventArgs info = new gsPrintEventArgs(PrintStatus_t.PRINT_ERROR, false, 0, this.m_first_page, this.m_num_pages, this.m_filename); PrintUpdate(this, info); return; } }