Gets or sets the rectangular area that represents the total area of the page.
public RectangleF PageRectangle { get; set; }
A System.Drawing.Rectangle represents the total area of the page.
This specifies the destination rectangle on the page to where the image is to be printed. Normally, you obtain the page rectangle through the System.Drawing.Printing.PrintPageEventArgs.MarginBounds or the System.Drawing.Printing.PrintPageEventArgs object passed to your System.Drawing.Printing.PrintPageEventHandler.
You can also pass RectangleF.Empty to use the whole print area. The print area will then be calculated using the UseMargins property value and the page and margins bounds values passed through System.Drawing.Printing.PrintPageEventArgs.
Important: the UseMargins property is only used to calculate the printing area when the value of both PageRectangle is left to the empty default value. If you set the PageRectangle value to anything else, it is assumed that you are responsible for calculating the print area and UseMargins will be ignored.
using Leadtools.WinForms;using Leadtools;using Leadtools.Codecs;// The image we are printingprivate RasterImage myImage = null;// The current page number being printedprivate int currentPrintPageNumber;public void RasterImagePrinterExample(){// Check if there are printers installed on this machineif (PrinterSettings.InstalledPrinters == null || PrinterSettings.InstalledPrinters.Count < 1){MessageBox.Show("There are no printers installed on this machine");return;}// Load the imageusing (RasterCodecs codecs = new RasterCodecs()){this.myImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"));}// Create the print document objectusing (PrintDocument document = new PrintDocument()){// Setup the document pagesdocument.PrinterSettings.MinimumPage = 1;document.PrinterSettings.MaximumPage = this.myImage.PageCount;document.PrinterSettings.FromPage = 1;document.PrinterSettings.ToPage = this.myImage.PageCount;DialogResult result = DialogResult.OK;// Select the printerusing (PrintDialog printDlg = new PrintDialog()){printDlg.Document = document;printDlg.AllowSomePages = true;result = printDlg.ShowDialog();}// Setup the pageif (result == DialogResult.OK){using (PageSetupDialog pageSetupDlg = new PageSetupDialog()){pageSetupDlg.Document = document;pageSetupDlg.ShowDialog();}}if (result == DialogResult.OK){// Add handlers for Begin/Print and End print eventsdocument.BeginPrint += new PrintEventHandler(document_BeginPrint);document.PrintPage += new PrintPageEventHandler(document_PrintPage);document.EndPrint += new PrintEventHandler(document_EndPrint);// Use the .NET print preview dialogusing (PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog()){printPreviewDlg.Document = document;printPreviewDlg.WindowState = FormWindowState.Maximized;result = printPreviewDlg.ShowDialog();}}}// Clean upthis.myImage.Dispose();}private void document_BeginPrint(object sender, PrintEventArgs e){// Reset the current page number// Since we are using the print preview dialog, this event will be called twice (once// to generate the print preview and once for actual printing). So, we must set this back// to the first print pagePrintDocument document = sender as PrintDocument;this.currentPrintPageNumber = document.PrinterSettings.FromPage;}private void document_EndPrint(object sender, PrintEventArgs e){// Nothing to do here}private void document_PrintPage(object sender, PrintPageEventArgs e){// Get the print document objectPrintDocument document = sender as PrintDocument;// Create an new LEADTOOLS image printer classRasterImagePrinter printer = new RasterImagePrinter();// Set the document object so page calculations can be performedprinter.PrintDocument = document;// We want to fit and center the image into the maximum print areaprinter.SizeMode = RasterPaintSizeMode.FitAlways;printer.HorizontalAlignMode = RasterPaintAlignMode.Center;printer.VerticalAlignMode = RasterPaintAlignMode.Center;// Account for FAX images that may have different horizontal and vertical resolutionprinter.UseDpi = true;// Print the whole imageprinter.ImageRectangle = Rectangle.Empty;// Use maximum page dimension ignoring the margins, this will be equivalant of printing// using Windows Photo Galleryprinter.PageRectangle = RectangleF.Empty;printer.UseMargins = false;// Print the current pageprinter.Print(this.myImage, this.currentPrintPageNumber, e);// Go to the next pagethis.currentPrintPageNumber++;// Inform the printer whether we have more pages to printif (this.currentPrintPageNumber <= document.PrinterSettings.ToPage)e.HasMorePages = true;elsee.HasMorePages = false;// De-couple our PrintDocument from the RasterImagePrinterprinter.PrintDocument = null;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";}