public void Print(PrinterSettings printerSettings, bool includeBackgroundObjects = true) { _printPageCount = 0; _includeBackgroundObjects = includeBackgroundObjects; var pageSizeInfo = GetPageSizeInfo(printerSettings); var portrait = true; if (_printerInteractionMode == PrinterInteractionMode.Active) { portrait = !printerSettings.DefaultPageSettings.Landscape; } PreRender(pageSizeInfo, includeBackgroundObjects, portrait); var doc = GetDocument(false, portrait); var docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); var printDocument = new MigraDocPrintDocument(); printDocument.PrintController = new StandardPrintController(); printDocument.PrintPage += PrintDocument_PrintPage; printDocument.Renderer = docRenderer; printDocument.PrinterSettings = printerSettings; printDocument.Print(); }
private void tobImprimir_Click(object sender, EventArgs e) { try { // Reuse the renderer from the preview DocumentRenderer renderer = this.pagePreview.Renderer; if (renderer != null) { int pageCount = renderer.FormattedDocument.PageCount; // Creates a PrintDocument that simplyfies printing of MigraDoc documents MigraDocPrintDocument printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = this.printerSettings; if (this.printerSettings.PrintRange == PrintRange.Selection) { printDocument.SelectedPage = this.pagePreview.Page; } // Attach the current document renderer printDocument.Renderer = renderer; // Print the document printDocument.Print(); } } catch { } }
private void ButtonDrukuj_Click(object sender, EventArgs e) { // Wykorzystaj ponownie renderer z podglądu wydruku var renderer = PodgladRaportu.Renderer; if (renderer == null) { return; } var pageCount = renderer.FormattedDocument.PageCount; // Tworzy PrintDocument, który upraszcza drukowanie dokumentu utworzonego przez MigraDoc var printDocument = new MigraDocPrintDocument(); // Dołącz istniejące ustawienia drukowania printDocument.PrinterSettings = UstawieniaDrukarki; if (UstawieniaDrukarki.PrintRange == PrintRange.Selection) { printDocument.SelectedPage = PodgladRaportu.Page; } // Dołącz istniejący renderer dokumentu printDocument.Renderer = renderer; // Wydrukowanie dokumentu printDocument.Print(); }
/// <summary> /// Demonstrates the preview using System.Windows.Froms.PrintPreviewDialog. /// In .NET 1.x this dialog is a lousy implementation. In .NET 2.0 it's a litte bit better /// (at least portrait/landscape is handled correctly...). /// </summary> private void miPreview_Click(object sender, System.EventArgs e) { using (PrintPreviewDialog dialog = new PrintPreviewDialog()) { dialog.Text = "Preview using System.Windows.Froms.PrintPreviewDialog"; #if NET_2_0 dialog.ShowIcon = false; #endif dialog.MinimizeBox = false; dialog.MaximizeBox = false; // Reuse the renderer from the preview DocumentRenderer renderer = this.pagePreview.Renderer; // Creates a PrintDocument that simplifies printing of MigraDoc documents MigraDocPrintDocument printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = this.printerSettings; // Attach the current document renderer printDocument.Renderer = renderer; // Attach the current print document dialog.Document = printDocument; // Show the preview dialog.ShowDialog(); } }
private void PrintDocument(PrinterSettings settings, Document document) { var printDocument = new MigraDocPrintDocument(document); printDocument.PrinterSettings = settings; printDocument.Print(); }
/// <summary> /// Prints the current document on a printer. /// </summary> private void MiPrintClick(object sender, EventArgs e) { #if true_ // TODO: MigraDoc.Rendering.Printing doesn't exist // Reuse the renderer from the preview var renderer = _pagePreview.Renderer; if (renderer == null) { return; } var pageCount = renderer.FormattedDocument.PageCount; // Creates a PrintDocument that simplifies printing of MigraDoc documents var printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = _printerSettings; if (_printerSettings.PrintRange == PrintRange.Selection) { printDocument.SelectedPage = _pagePreview.Page; } // Attach the current document renderer printDocument.Renderer = renderer; // Print the document printDocument.Print(); #endif }
/// <summary> /// Demonstrates the preview using System.Windows.Froms.PrintPreviewDialog. /// In .NET 1.x this dialog is a lousy implementation. In .NET 2.0 it's a little bit better /// (at least portrait/landscape is handled correctly...). /// </summary> private void MiPreviewClick(object sender, EventArgs e) { #if true_ // TODO: MigraDoc.Rendering.Printing doesn't exist using (var dialog = new PrintPreviewDialog()) { dialog.Text = "Preview using System.Windows.Froms.PrintPreviewDialog"; #if NET_2_0 dialog.ShowIcon = false; #endif dialog.MinimizeBox = false; dialog.MaximizeBox = false; // Reuse the renderer from the preview var renderer = _pagePreview.Renderer; // Creates a PrintDocument that simplifies printing of MigraDoc documents var printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = _printerSettings; // Attach the current document renderer printDocument.Renderer = renderer; // Attach the current print document dialog.Document = printDocument; // Show the preview dialog.ShowDialog(); } #endif }
void printButton_Click(object sender, RoutedEventArgs e) { if (_vm.SelectedProtocol == null) { MessageBox.Show("Please select an analysis protocol first", "No Protocol Selected", MessageBoxButton.OK, MessageBoxImage.Error); return; } var reportService = new ReportPdf(); var reportData = CreateReportData(); System.Windows.Forms.PrintDialog printDlg = new System.Windows.Forms.PrintDialog(); MigraDocPrintDocument printDoc = new MigraDocPrintDocument(); printDoc.Renderer = new MigraDoc.Rendering.DocumentRenderer(reportService.CreateReport(reportData)); printDoc.Renderer.PrepareDocument(); printDoc.DocumentName = Window.GetWindow(this).Title; //printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); printDlg.Document = printDoc; printDlg.AllowSelection = true; printDlg.AllowSomePages = true; //Call ShowDialog if (printDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { printDoc.Print(); } }
private void miPreview_Click(object sender, System.EventArgs e) { using (PrintPreviewDialog dialog = new PrintPreviewDialog()) { dialog.Text = "الاستعراض قبل الطباعة"; dialog.MinimizeBox = false; dialog.MaximizeBox = false; // Reuse the renderer from the preview DocumentRenderer renderer = preview.Renderer; // Creates a PrintDocument that simplifies printing of MigraDoc documents MigraDocPrintDocument printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = this.printerSettings; // Attach the current document renderer printDocument.Renderer = renderer; // Attach the current print document dialog.Document = printDocument; // Show the preview dialog.ShowDialog(); } }
public bool Print(IntPtr parentWindowHandle, string devSerial, string devFilename, bool previewOnly) { if (previewOnly == true) { return(Preview(parentWindowHandle, devSerial, devFilename)); } DocumentPreview preview = createPreview(devSerial, devFilename); if (preview == null) { return(false); } int numPages = preview.Renderer.FormattedDocument.PageCount; PrinterSettings printerSettings = new PrinterSettings(); printerSettings.FromPage = 1; printerSettings.ToPage = numPages; using (PrintDialog dialog = new PrintDialog()) { printerSettings.DefaultPageSettings.Landscape = false; dialog.PrinterSettings = printerSettings; dialog.AllowSelection = false; dialog.AllowSomePages = true; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } printerSettings = dialog.PrinterSettings; if (printerSettings.ToPage > numPages) { printerSettings.ToPage = numPages; } if (printerSettings.FromPage > numPages) { printerSettings.FromPage = 1; } var printDocument = new MigraDocPrintDocument(); printDocument.PrinterSettings = dialog.PrinterSettings; printDocument.Renderer = preview.Renderer; printDocument.Print(); } return(true); }
private bool Print() { try { // Reuse the renderer from the preview DocumentRenderer renderer = preview.Renderer; if (renderer != null) { int pageCount = renderer.FormattedDocument.PageCount; // Creates a PrintDocument that simplyfies printing of MigraDoc documents MigraDocPrintDocument printDocument = new MigraDocPrintDocument(); // Attach the current printer settings printDocument.PrinterSettings = this.printerSettings; if (this.printerSettings.PrintRange == PrintRange.Selection) { printDocument.SelectedPage = preview.Page; } // Attach the current document renderer printDocument.Renderer = renderer; // Print the document printDocument.Print(); return(true); } else { return(false); } } catch { return(false); } }