/// <summary> /// The actual method to print a page /// </summary> /// <param name="e">PrintPageEventArgs</param> /// <param name="sizeOnly">Indicates that only sizing is done</param> /// <returns>True if there are more pages</returns> protected virtual bool PrintAPage (PrintPageEventArgs e, bool sizeOnly) { #if BYPASS_PRINTABLE_AREA_LOGIC Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; // Bypass "tricky" page margins that take into account printer limits float leftMargin = e.MarginBounds.Left * scale; float topMargin = e.MarginBounds.Top * scale; float rightMargin = e.MarginBounds.Right * scale; float bottomMargin = e.MarginBounds.Bottom * scale; Bounds pageBounds = new Bounds(leftMargin, topMargin, rightMargin, bottomMargin); #else Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; IntPtr hDc = e.Graphics.GetHdc(); PrinterMarginInfo mi = new PrinterMarginInfo(hDc.ToInt32()); e.Graphics.ReleaseHdc(hDc); Bounds pageBounds = mi.GetBounds (e.PageBounds, e.MarginBounds, scale); #endif // Header if (this.PageHeader != null) { Bounds headerBounds = pageBounds; if (this.PageHeaderMaxHeight > 0) { headerBounds.Limit.Y = headerBounds.Position.Y + this.PageHeaderMaxHeight; } this.PageHeader.Print(this, g, headerBounds); pageBounds.Position.Y += this.PageHeader.Size.Height; } // Footer if (this.PageFooter != null) { Bounds footerBounds = pageBounds; if (this.PageFooterMaxHeight > 0) { footerBounds.Position.Y = footerBounds.Limit.Y - this.PageFooterMaxHeight; } this.PageFooter.CalcSize (this, g, footerBounds); footerBounds = footerBounds.GetBounds (this.PageFooter.Size, this.PageFooter.HorizontalAlignment, this.PageFooter.VerticalAlignment); this.PageFooter.Print (this, g, footerBounds); pageBounds.Limit.Y -= this.PageFooter.Size.Height; } // Body if (this.Body != null) { this.Body.Print(this, g, pageBounds); e.HasMorePages = this.Body.Continued; } else { e.HasMorePages = false; } return e.HasMorePages; } // OnPrintPage
/// <summary> /// The actual method to print a page /// </summary> /// <param name="e">PrintPageEventArgs</param> /// <param name="sizeOnly">Indicates that only sizing is done</param> /// <returns>True if there are more pages</returns> protected virtual bool PrintAPage(PrintPageEventArgs e, bool sizeOnly) { #if BYPASS_PRINTABLE_AREA_LOGIC Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; // Bypass "tricky" page margins that take into account printer limits float leftMargin = e.MarginBounds.Left * scale; float topMargin = e.MarginBounds.Top * scale; float rightMargin = e.MarginBounds.Right * scale; float bottomMargin = e.MarginBounds.Bottom * scale; Bounds pageBounds = new Bounds(leftMargin, topMargin, rightMargin, bottomMargin); #else Graphics g = e.Graphics; g.PageUnit = DocumentUnit; // Define page bounds (margins are always in inches) float scale = GetScale() / 100; IntPtr hDc = e.Graphics.GetHdc(); PrinterMarginInfo mi = new PrinterMarginInfo(hDc.ToInt32()); e.Graphics.ReleaseHdc(hDc); Bounds pageBounds = mi.GetBounds(e.PageBounds, e.MarginBounds, scale); #endif // Header if (this.PageHeader != null) { Bounds headerBounds = pageBounds; if (this.PageHeaderMaxHeight > 0) { headerBounds.Limit.Y = headerBounds.Position.Y + this.PageHeaderMaxHeight; } this.PageHeader.Print(this, g, headerBounds); pageBounds.Position.Y += this.PageHeader.Size.Height; } // Footer if (this.PageFooter != null) { Bounds footerBounds = pageBounds; if (this.PageFooterMaxHeight > 0) { footerBounds.Position.Y = footerBounds.Limit.Y - this.PageFooterMaxHeight; } this.PageFooter.CalcSize(this, g, footerBounds); footerBounds = footerBounds.GetBounds(this.PageFooter.Size, this.PageFooter.HorizontalAlignment, this.PageFooter.VerticalAlignment); this.PageFooter.Print(this, g, footerBounds); pageBounds.Limit.Y -= this.PageFooter.Size.Height; } // Body if (this.Body != null) { this.Body.Print(this, g, pageBounds); e.HasMorePages = this.Body.Continued; } else { e.HasMorePages = false; } return(e.HasMorePages); } // OnPrintPage