private void DoPrint(C1PdfDocumentSource pds) { printDialog.MaxPage = (uint)pds.PageCount; bool?dr = printDialog.ShowDialog(); if (!dr.HasValue || !dr.Value) { return; } try { var po = new C1PrintOptions(); po.PrintQueue = printDialog.PrintQueue; po.PrintTicket = printDialog.PrintTicket; if (printDialog.PageRangeSelection == PageRangeSelection.UserPages) { po.OutputRange = new OutputRange(printDialog.PageRange.PageFrom, printDialog.PageRange.PageTo); } pds.Print(po); MessageBox.Show(this, "Document was successfully printed.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { if (_report.IsBusy) { return; } string selectedReport = cbReport.SelectedItem as string; if (string.IsNullOrEmpty(selectedReport)) { return; } PrintInfo pi = cbPrinter.SelectedItem as PrintInfo; if (pi == null) { return; } // load report try { // load from resource stream Assembly asm = Assembly.GetExecutingAssembly(); using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_XML.flxr")) _report.Load(stream, selectedReport); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to load report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // render and print report try { _report.Render(); C1PrintOptions po = new C1PrintOptions(); po.PrintQueue = pi.PrintQueue; _report.Print(po); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to print report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void DoPrint(C1PdfDocumentSource pds) { if (printDialog1.ShowDialog(this) != DialogResult.OK) { return; } try { C1PrintOptions po = new C1PrintOptions(); po.PrinterSettings = printDialog1.PrinterSettings; pds.Print(po); MessageBox.Show(this, "Document was successfully printed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { if (cbPrinter.SelectedItem == null) { MessageBox.Show("Please select a printer.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // load document while (true) { try { if (fpFile.SelectedFile == null) { using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(@"PdfDocumentSourceSamples.Resources.DefaultDocument.pdf")) pdfDocumentSource.LoadFromStream(stream); } else { pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName); } break; } catch (PdfPasswordException) { var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName); if (password == null) { return; } pdfDocumentSource.Credential.Password = password; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } // OutputRange outputRange; if (rbtnPagesAll.IsChecked.Value) { outputRange = OutputRange.All; } else { if (!OutputRange.TryParse(tbPagesRange.Text, out outputRange)) { MessageBox.Show("Invalid range of pages.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } try { C1PrintOptions po = new C1PrintOptions(); po.PrintQueue = (PrintQueue)((C1ComboBoxItem)cbPrinter.SelectedItem).Tag; po.OutputRange = outputRange; pdfDocumentSource.Print(po); MessageBox.Show("Document was successfully printed.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }