/// <summary> /// The PageLayoutingEvent event handler called before each PDF page is rendered by the converter /// </summary> /// <param name="eventParams">The event handler parameter giving information about the PDF page being rendered /// and the rectangle in page that will be rendered</param> void htmlToPdfConverter_PageLayoutingEvent(PdfPageLayoutingParams eventParams) { // The PDF page being rendered PdfPage crtPage = eventParams.PdfPage; // draw a colored rectangle in the background of the PDF page PdfRectangle backColorRect = new PdfRectangle(0, 0, crtPage.DrawableRectangle.Width, crtPage.DrawableRectangle.Height); backColorRect.BackColor = System.Drawing.Color.FromArgb(255, int.Parse(textBoxR.Text), int.Parse(textBoxG.Text), int.Parse(textBoxB.Text)); crtPage.Layout(backColorRect); // draw a 2 points orange line under the rendered content in page System.Drawing.PointF leftBottom = new System.Drawing.PointF(eventParams.LayoutingBounds.Left, eventParams.LayoutingBounds.Bottom + 1); System.Drawing.PointF rightBottom = new System.Drawing.PointF(eventParams.LayoutingBounds.Right, eventParams.LayoutingBounds.Bottom + 1); PdfLine bottomLine = new PdfLine(leftBottom, rightBottom); bottomLine.LineStyle.LineWidth = 2.0f; bottomLine.ForeColor = System.Drawing.Color.OrangeRed; crtPage.Layout(bottomLine); }
/// <summary> /// /// </summary> /// <param name="eventParams"></param> private void htmlToPdfConverter_PageLayoutingEvent(PdfPageLayoutingParams eventParams) { if ((templateOption != null) && (templateOption.PageMargin != null)) { PdfPage page = eventParams.PdfPage; PdfLine leftLine = new PdfLine(new System.Drawing.PointF(leftStartXPoint, 0), new System.Drawing.PointF(leftStartXPoint, page.DrawableRectangle.Height)); PdfLine rightLine = new PdfLine(new System.Drawing.PointF((float)(page.DrawableRectangle.Width - 2.5), 0), new System.Drawing.PointF((float)(page.DrawableRectangle.Width - 2.5), page.DrawableRectangle.Height)); PdfFont font = page.Document.CreateStandardFont(PdfStandardFont.TimesRoman); //Border Color for the PDF if (!string.IsNullOrEmpty(templateOption.PageMargin.Color)) { leftLine.ForeColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color); leftLine.BackColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color); rightLine.ForeColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color); rightLine.BackColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color); } page.Layout(leftLine); page.Layout(rightLine); } }