private void AddFooters() { Font fontHorz = new Font("Tahoma", 7, FontStyle.Bold); StringFormat sfRight = new StringFormat(); sfRight.Alignment = StringAlignment.Far; for (int page = 0; page < PdfCotizacion.Pages.Count; page++) { // select page we want (could change PageSize) PdfCotizacion.CurrentPage = page; // build rectangles for rendering text RectangleF rcPage = GetPageRect(); RectangleF rcFooter = rcPage; rcFooter.Y = rcFooter.Bottom + 6; rcFooter.Height = 12; RectangleF rcVert = rcPage; rcVert.X = rcPage.Right + 6; // add left-aligned footer string text = AppSettings.NomSede + " - " + AppSettings.UbicacionSede + " TEL: " + AppSettings.TelfSede; PdfCotizacion.DrawString(text, fontHorz, Brushes.Black, rcFooter); // add right-aligned footer string TextVertical = string.Format("Page {0} of {1}", page + 1, PdfCotizacion.Pages.Count); PdfCotizacion.DrawString(TextVertical, fontHorz, Brushes.Black, rcFooter, sfRight); // draw lines on bottom and right of the page PdfCotizacion.DrawLine(Pens.Black, rcPage.Left, rcPage.Bottom, rcPage.Right, rcPage.Bottom); } }
private RectangleF RenderTableHeader(Font font, RectangleF rc, params string[] fields) { // calculate cell width (same for all columns) RectangleF rcCell = rc; rcCell.Width = rc.Width / fields.Length; rcCell.Height = 0; // calculate cell height (max of all columns) foreach (string field in fields) { float height = PdfCotizacion.MeasureString(field, font, rcCell.Width).Height; rcCell.Height = Math.Max(rcCell.Height, height); } // render header cells StringFormat sf = new StringFormat(); foreach (string field in fields) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; PdfCotizacion.FillRectangle(Brushes.Black, rcCell); PdfCotizacion.DrawString(field, font, Brushes.White, rcCell, sf); rcCell.Offset(rcCell.Width, 0); } // update rectangle and return it rc.Offset(0, rcCell.Height); return(rc); }
private RectangleF RenderTableRow(Font font, Font hdrFont, RectangleF rcPage, RectangleF rc, string[] fields, DataRow dr) { // calculate cell width (same for all columns) RectangleF rcCell = rc; rcCell.Width = rc.Width / fields.Length; rcCell.Height = 0; // calculate cell height (max of all columns) rcCell.Inflate(-4, 0); foreach (string field in fields) { string text = dr[field].ToString(); float height = PdfCotizacion.MeasureString(text, font, rcCell.Width).Height; rcCell.Height = Math.Max(rcCell.Height, height); } rcCell.Inflate(4, 0); // break page if we have to if (rcCell.Bottom > rcPage.Bottom) { PdfCotizacion.NewPage(); rc = RenderTableHeader(hdrFont, rcPage, fields); rcCell.Y = rc.Y; } // center vertically just to show how StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Near; // render data cells Pen pen = new Pen(Brushes.Blue, 0.1f); foreach (string field in fields) { // get content string text = dr[field].ToString(); // set horizontal alignment double d; sf.Alignment = (double.TryParse(text, NumberStyles.Any, CultureInfo.CurrentCulture, out d)) ? StringAlignment.Near : StringAlignment.Near; // render cell PdfCotizacion.DrawRectangle(pen, rcCell); rcCell.Inflate(-4, 0); PdfCotizacion.DrawString(text, font, Brushes.Black, rcCell, sf); rcCell.Inflate(4, 0); rcCell.Offset(rcCell.Width, 0); } pen.Dispose(); // update rectangle and return it rc.Offset(0, rcCell.Height); return(rc); }
internal RectangleF RenderParagraph(string text, Font font, RectangleF rcPage, RectangleF rc, bool outline, int Tipo) { // if it won't fit this page, do a page break rc.Height = PdfCotizacion.MeasureString(text, font, rc.Width).Height; if (rc.Bottom > rcPage.Bottom) { PdfCotizacion.NewPage(); rc.Y = rcPage.Top; } // draw the string StringFormat sf = new StringFormat(); if (Tipo == 1) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf); } else if (Tipo == 2) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Near; PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf); } else if (Tipo == 3) { sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Far; PdfCotizacion.DrawString(text, font, Brushes.Black, rc, sf); } //add headings to outline if (outline) { PdfCotizacion.DrawLine(Pens.Black, rc.X, rc.Y, rc.Right, rc.Y); } // update rectangle for next time rc.Offset(0, rc.Height); return(rc); }