private void _printDocument_PrintPage(object sender, PrintPageEventArgs e) { RasterImage image = _viewerControl.ImageViewer.Image; // Get the print document object PrintDocument document = sender as PrintDocument; // Create an new LEADTOOLS image printer class RasterImagePrinter printer = new RasterImagePrinter(); // Set the document object so page calculations can be performed printer.PrintDocument = document; // We want to fit and center the image into the maximum print area printer.SizeMode = RasterPaintSizeMode.FitAlways; printer.HorizontalAlignMode = RasterPaintAlignMode.Center; printer.VerticalAlignMode = RasterPaintAlignMode.Center; // Account for FAX images that may have different horizontal and vertical resolution printer.UseDpi = true; // Print the whole image printer.ImageRectangle = Rectangle.Empty; // Use maximum page dimension ignoring the margins, this will be equivalant of printing // using Windows Photo Gallery printer.PageRectangle = RectangleF.Empty; printer.UseMargins = false; // Print the current page printer.Print(image, _currentPrintPageNumber, e); // Go to the next page _currentPrintPageNumber++; // Inform the printer whether we have more pages to print if (_currentPrintPageNumber <= document.PrinterSettings.ToPage) { e.HasMorePages = true; } else { e.HasMorePages = false; } }
void _printDocument_PrintPage(object sender, PrintPageEventArgs e) { try { using (RasterImage _img = _CurrCell.Image.CloneAll()) { ColorResolutionCommand colorResolutionCommand = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, _img.BitsPerPixel, _img.Order, _img.DitheringMethod, ColorResolutionCommandPaletteFlags.None, null); colorResolutionCommand.Run(_img); // Get the print document object PrintDocument document = sender as PrintDocument; if (!AutoPageSettings)//Nếu lấy cấu hình in từ tùy chọn Cấu hình in lazer thì cần thiết lập lại một số thông số cho đối tượng in { PageSettings ps = Getps(); document.PrinterSettings.DefaultPageSettings.Margins = ps.Margins; document.PrinterSettings.DefaultPageSettings.PaperSize = ps.PaperSize; document.PrinterSettings.DefaultPageSettings.Landscape = ps.Landscape; } document.PrinterSettings.PrinterName = _LazerPrinterName; // Create an new LEADTOOLS image printer class RasterImagePrinter printer = new RasterImagePrinter(); // Set the document object so page calculations can be performed printer.PrintDocument = document; // We want to fit and center the image into the maximum print area printer.SizeMode = RasterPaintSizeMode.FitAlways; printer.HorizontalAlignMode = RasterPaintAlignMode.Center; printer.VerticalAlignMode = RasterPaintAlignMode.Center; // Account for FAX images that may have different horizontal and vertical resolution printer.UseDpi = true; // Print the whole image printer.ImageRectangle = Rectangle.Empty; // Use maximum page dimension ignoring the margins, this will be equivalant of printing // using Windows Photo Gallery printer.PageRectangle = RectangleF.Empty; printer.UseMargins = false; // Print the current page printer.Print(_img, _img.Page, e); // Inform the printer we have no more pages to print e.HasMorePages = false; } } catch (Exception ex) { Utility.ShowMsg("Lỗi khi đẩy dữ liệu ảnh ra máy in:\n" + ex.Message, "Thông báo lỗi"); } }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) { RasterImage image = (_imageList.ActiveItem as PDFPageItem).PageImage; // Get the print document object PrintDocument document = sender as PrintDocument; // Create an new LEADTOOLS image printer class RasterImagePrinter printer = new RasterImagePrinter(); // Set the document object so page calculations can be performed printer.PrintDocument = document; // We want to fit and center the image into the maximum print area printer.SizeMode = RasterPaintSizeMode.FitAlways; printer.HorizontalAlignMode = RasterPaintAlignMode.Center; printer.VerticalAlignMode = RasterPaintAlignMode.Center; // Account for FAX images that may have different horizontal and vertical resolution printer.UseDpi = true; // Print the whole image printer.ImageRectangle = Rectangle.Empty; // Use maximum page dimension ignoring the margins, this will be equivalant of printing // using Windows Photo Gallery printer.PageRectangle = RectangleF.Empty; printer.UseMargins = false; using (Image printImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.None)) { using (Bitmap printBitmap = new Bitmap(printImage)) { foreach (FormFieldControl control in _imageViewer.Controls) { if (control.IsFieldPrintable) { bool isFieldVisible = control.IsFieldVisible; control.IsFieldVisible = true; LeadRect leadBounds = new LeadRect(control.Bounds.X, control.Bounds.Y, control.FiedlBounds.Width, control.Bounds.Height); // convert from Control to Image coordinates leadBounds = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, leadBounds); Rectangle bounds = new Rectangle(leadBounds.X, leadBounds.Y, leadBounds.Width, leadBounds.Height); control.DrawToBitmap(printBitmap, bounds); control.IsFieldVisible = isFieldVisible; } } image = RasterImageConverter.ConvertFromImage(printBitmap, ConvertFromImageOptions.None); } } // Print the current page printer.Print(image, _currentPrintPageNumber, e); // Go to the next page _currentPrintPageNumber++; // Inform the printer whether we have more pages to print if (_currentPrintPageNumber <= document.PrinterSettings.ToPage) { e.HasMorePages = true; } else { e.HasMorePages = false; } }