public DrawString ( string s, XFont font, XBrush brush, PointF point ) : void | ||
s | string | |
font | XFont | |
brush | XBrush | |
point | PointF | |
return | void |
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string facename = "Times"; XFont fontR = new XFont(facename, 40); XFont fontB = new XFont(facename, 40, XFontStyle.Bold); XFont fontI = new XFont(facename, 40, XFontStyle.Italic); XFont fontBI = new XFont(facename, 40, XFontStyle.Bold | XFontStyle.Italic); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); double x = 80; XPen pen = XPens.SlateBlue; gfx.DrawLine(pen, x, 100, x, 600); gfx.DrawLine(pen, x - 50, 200, 400, 200); gfx.DrawLine(pen, x - 50, 300, 400, 300); gfx.DrawLine(pen, x - 50, 400, 400, 400); gfx.DrawLine(pen, x - 50, 500, 400, 500); double lineSpace = fontR.GetHeight(gfx); int cellSpace = fontR.FontFamily.GetLineSpacing(fontR.Style); int cellAscent = fontR.FontFamily.GetCellAscent(fontR.Style); int cellDescent = fontR.FontFamily.GetCellDescent(fontR.Style); double cyAscent = lineSpace * cellAscent / cellSpace; XFontMetrics metrics = fontR.Metrics; XSize size; gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200); size = gfx.MeasureString("Times 40", fontR); gfx.DrawLine(this.properties.Pen3.Pen, x, 200, x + size.Width, 200); gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300); size = gfx.MeasureString("Times bold 40", fontB); //gfx.DrawLine(this.properties.Pen3.Pen, x, 300, x + size.Width, 300); gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400); size = gfx.MeasureString("Times italic 40", fontI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 400, x + size.Width, 400); gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500); size = gfx.MeasureString("Times bold italic 40", fontBI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 500, x + size.Width, 500); #if true___ // Check Malayalam XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont Kartika = new XFont("Kartika", 20, XFontStyle.Regular, options); XFont AnjaliOldLipi = new XFont("AnjaliOldLipi", 20, XFontStyle.Regular, options); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", Kartika, this.properties.Font1.Brush, x, 600); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", AnjaliOldLipi, this.properties.Font1.Brush, x, 650); #endif }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string text = "TgfÄÖÜWi9"; if (this.properties.Font1.Text != "") text = this.properties.Font1.Text; float x = 100, y = 300; string familyName = properties.Font1.FamilyName; XFontStyle style = this.properties.Font1.Style; float emSize = this.properties.Font1.Size; //familyName = "Verdana"; //style = XFontStyle.Regular; //emSize = 20; //text = "X"; XFont font = CreateFont(familyName, emSize, style); //font = this.properties.Font1.Font; XSize size = gfx.MeasureString(text, font); double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); double descent = lineSpace * cellDescent / cellSpace; gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); double leading = lineSpace * cellLeading / cellSpace; gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height); //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); #if true_ XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true); font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions); text = "Hallo"; text = chinese; #endif gfx.DrawString(text, font, this.properties.Font1.Brush, x, y); #if true XFont font2 = CreateFont(familyName, emSize, XFontStyle.Italic); gfx.DrawString(text, font2, this.properties.Font1.Brush, x, y+50); #endif //gfx.DrawLine(XPens.Red, x, y + 10, x + 13.7, y + 10); //gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20); }
public void DrawBarCharts(XGraphics gfx) { XPoint backgroundPoint = new XPoint(20, page_.Height * 0.55); XRect backgroundRect = new XRect(backgroundPoint.X, backgroundPoint.Y, page_.Width - 40, page_.Height * 0.425); double quarterRectWidth = backgroundRect.Width * 0.25; double offset = quarterRectWidth * 0.25; DrawingUtil.DrawOutlineRect(backgroundRect, gfx, new XSize(40,40)); gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)), backgroundRect, new XSize(40, 40)); DoubleBar ShoulderFlexionBar = new DoubleBar(userParameters_[dataReadStart + 4], userParameters_[dataReadStart + 9], gfx); ShoulderFlexionBar.Draw(new XPoint(quarterRectWidth - offset, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png")); DoubleBar hipFlexionBar = new DoubleBar(userParameters_[dataReadStart + 5], userParameters_[dataReadStart + 10], gfx); hipFlexionBar.Draw(new XPoint(quarterRectWidth * 2 - offset, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png")); DoubleBar kneeFlexionBar = new DoubleBar(userParameters_[dataReadStart + 6], userParameters_[dataReadStart + 11], gfx); kneeFlexionBar.Draw(new XPoint(quarterRectWidth * 3 - offset, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png")); DoubleBar ankleFlexionBar = new DoubleBar(userParameters_[dataReadStart + 7], userParameters_[dataReadStart + 12], gfx); ankleFlexionBar.Draw(new XPoint(quarterRectWidth * 4 - offset, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\DOS.png")); gfx.DrawString("Degrees :", new XFont("Arial", 10), XBrushes.Black, (backgroundPoint + new XPoint(0, 20)) + new XPoint(backgroundRect.Width * 0.05, backgroundRect.Height * 0.05), XStringFormats.Center); gfx.DrawString("LSI % :", new XFont("Arial", 10), XBrushes.Black, (backgroundPoint + new XPoint(0, 20)) + new XPoint(backgroundRect.Width * 0.05, backgroundRect.Height * 0.125), XStringFormats.Center); XPoint top = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.2); XPoint bottom = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.8); for (int i = 11; i > 0; i--) { float increment = -i * 0.1f; XPoint percentagePoint = DrawingUtil.Instance.Interpolate(top, bottom, increment); percentagePoint = new XPoint(percentagePoint.X, Math.Floor(percentagePoint.Y)); gfx.DrawString(((11 - i) * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, percentagePoint + new XPoint(5, -2)); gfx.DrawLine(XPens.LightGray, percentagePoint, percentagePoint + new XPoint(backgroundRect.Width, 0)); } }
void RenderMeasureText(XGraphics gfx) { gfx.TranslateTransform(15, 20); XFontStyle style = XFontStyle.Regular; XFont font = new XFont("Times New Roman", 95, style); string text = "Hello"; double x = 20, y = 100; XSize size = gfx.MeasureString(text, font); double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; // Get effective ascent double ascent = lineSpace * cellAscent / cellSpace; gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); // Get effective descent double descent = lineSpace * cellDescent / cellSpace; gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); // Get effective leading double leading = lineSpace * cellLeading / cellSpace; gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); // Draw text half transparent XColor color = XColors.DarkSlateBlue; color.A = 0.6; gfx.DrawString(text, font, new XSolidBrush(color), x, y); }
void RenderTextStyles(XGraphics gfx) { gfx.TranslateTransform(15, 20); string facename = "Times New Roman"; XFont fontRegular = new XFont(facename, 20); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString("Times (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString("Times (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString("Times (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString("Times (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); }
public void DrawPage(XGraphics gfx, PointF pagepos, PageDrawOptions opts) { float acty = 0; for (int i = 0; i < m_noDelimPageCount; i++) { Pane pane = m_panes[i]; pane.Draw(gfx, new PointF(pagepos.X, pagepos.Y + acty), true); acty += pane.Height; } if (opts != null) { string header = opts.Header.Replace("%c", PageNumber.ToString()); string footer = opts.Footer.Replace("%c", PageNumber.ToString()); if (header != "") { float hdrwi = (float)gfx.MeasureString(header, opts.HeaderFont).Width; float hdrhi = (float)gfx.MeasureString(header, opts.HeaderFont).Height; gfx.DrawString(header, opts.HeaderFont, opts.HeaderColor, new PointF(pagepos.X + opts.PageWidth / 2 - hdrwi / 2, pagepos.Y - hdrhi), XStringFormat.TopLeft); } if (footer != "") { float ftrwi = (float)gfx.MeasureString(footer, opts.FooterFont).Width; gfx.DrawString(footer, opts.FooterFont, opts.FooterColor, new PointF(pagepos.X + opts.PageWidth / 2 - ftrwi / 2, pagepos.Y + opts.PageHeight), XStringFormat.TopLeft); } } }
public override void RenderPage(XGraphics gfx) { //base.RenderPage(gfx); XFont font1 = new XFont("Arial", 9); XFont font2 = new XFont("Arial", 9, XFontStyle.Italic); XFont font3 = new XFont("Arial", 9, XFontStyle.Bold); XSolidBrush brush = new XSolidBrush(XColors.Black); gfx.DrawString("Page 5", font1, brush, 100, 100); gfx.DrawString("Water Sports You've Done continued", font2, brush, 100, 200); gfx.DrawString("Rowing", font1, brush, 100, 250); gfx.DrawString("Snorkeling", font1, brush, 100, 300); gfx.DrawString("WINTER SPORTS, SKIING, SKIING IN THE US", font3, XBrushes.Red, 100, 320); gfx.DrawLine(XPens.Red, 100, 100, 200, 200); gfx.DrawString("Resorts You've Skied in Vermont", font3, brush, 100, 400); gfx.DrawString("Haystack", font1, brush, 100, 420); // string text = "TgfÄÖÜWi9"; // if (this.properties.Font1.Text != "") // text = this.properties.Font1.Text; // float x = 100, y = 300; // string familyName = properties.Font1.FamilyName; // XFontStyle style = this.properties.Font1.Style; // float emSize = this.properties.Font1.Size; // XFont font = CreateFont(familyName, emSize, style); // font = this.properties.Font1.Font; // XSize size = gfx.MeasureString(text, font); // double lineSpace = font.GetHeight(gfx); // int cellSpace = font.FontFamily.GetLineSpacing(style); // int cellAscent = font.FontFamily.GetCellAscent(style); // int cellDescent = font.FontFamily.GetCellDescent(style); // int cellLeading = cellSpace - cellAscent - cellDescent; // double ascent = lineSpace * cellAscent / cellSpace; // gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); // double descent = lineSpace * cellDescent / cellSpace; // gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); // double leading = lineSpace * cellLeading / cellSpace; // gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); // //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height); // //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y); // //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); //#if true_ // XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true); // font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions); // text = "Hallo"; // text = chinese; //#endif // gfx.DrawString(text, font, this.properties.Font1.Brush, x, y); // gfx.DrawLine(XPens.Red, 0, 0, 100, 100); // gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20); }
static void RenderTextStyles(XGraphics gfx) { gfx.TranslateTransform(15, 20); const string facename = "Segoe UI"; //const string facename = "Frutiger LT 55 Roman,Frutiger LT 45 Light"; XFont fontRegular = new XFont(facename, 20); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString(facename + " (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString(facename + " (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString(facename + " (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString(facename + " (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); }
/// <summary> /// Draws text in different styles. /// </summary> void DrawText(XGraphics gfx, int number) { BeginBox(gfx, number, "Text Styles"); string facename = "Times New Roman"; XFont fontRegular = new XFont(facename, 20); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString("Times (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString("Times (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString("Times (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString("Times (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); EndBox(gfx); }
static void RenderTextStyles(XGraphics gfx) { gfx.TranslateTransform(15, 20); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); const string facename = "Times New Roman"; XFont fontRegular = new XFont(facename, 20, XFontStyle.Regular, options); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold, options); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic, options); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic, options); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString(facename +" (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString(facename + " (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString(facename + " (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString(facename +" (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); }
/// <summary> /// Renders the content of the page. /// </summary> public void Render(XGraphics xGraphics) { const double textPossitionX = 50; double textPossitionY = 100; const string fontFamilyName = "Times"; const int fontSizeHeader = 18; const int fontSizeText = 12; XFont fontHeader = new XFont(fontFamilyName, fontSizeHeader, XFontStyle.Bold); XFont fontText = new XFont(fontFamilyName, fontSizeText); XFont fontItalic = new XFont(fontFamilyName, fontSizeText, XFontStyle.BoldItalic); double lineSpacing = fontText.GetHeight(xGraphics); xGraphics.DrawString("This is Header", fontHeader, XBrushes.Black, textPossitionX, textPossitionX); textPossitionY += lineSpacing; xGraphics.DrawString("This is normal.", fontText, XBrushes.Black, textPossitionX, textPossitionY); textPossitionY += lineSpacing; xGraphics.DrawString("This is Italic.", fontItalic, XBrushes.Black, textPossitionX, textPossitionY); textPossitionY += lineSpacing*3; //Bitmap bitmap = (Bitmap)Image.FromFile(@"E:\temp\klicaj.jpeg"); XImage xImage = null; if (item != null) { if (item.Image != null) { MemoryStream memoryStream = new MemoryStream(item.Image); Bitmap bitmap = (Bitmap) Image.FromStream(memoryStream, true, true); xImage = XImage.FromGdiPlusImage(bitmap); } } if (xImage != null) { XRect rcImage = new XRect(100, textPossitionY, 100, 100*Math.Sqrt(2)); xGraphics.DrawImage(xImage, rcImage); } XGraphicsState state = xGraphics.Save(); xGraphics.Restore(state); }
public void Draw(XGraphics gfx) { string s = "Testtext"; //gfx.DrawLine(XPens.GreenYellow, 5, 100, 30, 50); //gfx.DrawEllipse(XBrushes.DarkBlue, new XRect(30, 40, 250, 235)); XFont font = new XFont("Arial", 40, XFontStyle.Italic); gfx.DrawString(s, font, XBrushes.Firebrick, 40, 60); XSize size = gfx.MeasureString(s, font); gfx.DrawLine(XPens.DarkBlue, 40, 60, 40 + size.Width, 60); gfx.DrawLine(XPens.DarkBlue, 40, 60, 40, 60 + size.Height); }
/// <summary> /// Draws the page title and footer. /// </summary> public void DrawTitle(PdfPage page, XGraphics gfx, string title) { XRect rect = new XRect(new XPoint(), gfx.PageSize); rect.Inflate(-10, -15); XFont font = new XFont("Verdana", 14, XFontStyle.Bold); gfx.DrawString(title, font, XBrushes.MidnightBlue, rect, XStringFormats.TopCenter); rect.Offset(0, 5); font = new XFont("Verdana", 8, XFontStyle.Italic); XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Near; format.LineAlignment = XLineAlignment.Far; gfx.DrawString("Created with " + PdfSharp.ProductVersionInfo.Producer, font, XBrushes.DarkOrchid, rect, format); font = new XFont("Verdana", 8); format.Alignment = XStringAlignment.Center; gfx.DrawString(Program.s_document.PageCount.ToString(), font, XBrushes.DarkOrchid, rect, format); Program.s_document.Outlines.Add(title, page, true); }
public override void RenderPage(XGraphics gfx) { //base.RenderPage(gfx); XFont font1 = new XFont("Times New Roman", 12); XFont font2 = new XFont("Courier New", 10, XFontStyle.Bold); gfx.WriteComment("Word 11"); gfx.DrawString("Word 11", font1, XBrushes.Black, new XPoint(50, 100)); gfx.WriteComment("Word 12"); gfx.DrawString("Word 12", font1, XBrushes.Black, new XPoint(100, 100)); gfx.WriteComment("Word 21"); gfx.DrawString("Word 21", font2, XBrushes.Black, new XPoint(50, 200)); gfx.WriteComment("Word 22"); gfx.DrawString("Word 22", font2, XBrushes.Black, new XPoint(100, 200)); gfx.WriteComment("Word 23"); gfx.DrawString("Word 22", font2, XBrushes.Red, new XPoint(150, 200)); gfx.WriteComment("Word 24"); gfx.DrawString("Word 24", font2, XBrushes.Red, new XPoint(200, 200)); }
/// <summary> /// Draws text in different styles. /// </summary> void DrawText(XGraphics gfx, int number) { BeginBox(gfx, number, "Text Styles"); const string facename = "Times New Roman"; //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Default); XFont fontRegular = new XFont(facename, 20, XFontStyle.Regular, options); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold, options); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic, options); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic, options); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString("Times (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString("Times (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString("Times (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString("Times (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); EndBox(gfx); }
protected void DrawGridlines(XGraphics gfx) { XPen majorpen = XPens.DarkGray.Clone(); majorpen.Width = 1; XPen minorpen = XPens.LightGray.Clone(); minorpen.Width = 0.1f; gfx.SmoothingMode = XSmoothingMode.HighSpeed; DrawGridlines(gfx, new XPoint(100, 100), majorpen, 100, minorpen, 10); string text = this.Description; XFont font = new XFont("Verdana", 14, XFontStyle.Bold); XSize size = gfx.MeasureString(text, font); gfx.DrawString(text, font, XBrushes.Black, (600 - size.Width) / 2, 30); }
void DrawCodePage(XGraphics gfx, XPoint origin) { const double dx = 25; const double dy = 25; XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold); //XFont font = new XFont("Bauhaus", 16); XFont font = this.properties.Font1.Font; //XFont labelFont = font; //font = new XFont("Symbol", 16); Encoding encoding = Encoding.GetEncoding(1252); double asdf = XColors.LightGray.GS; //XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1)); XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9)); XFontStyle style = font.Style; double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; double descent = lineSpace * cellDescent / cellSpace; double leading = lineSpace * cellLeading / cellSpace; double x = origin.X + dx; double y = origin.Y; //for (int idx = 0; idx < 16; idx++) // gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y); for (int row = 0; row < 16; row++) { x = origin.X; y += dy; //gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y); for (int clm = 0; clm < 16; clm++) { x += dx; string glyph = encoding.GetString(new byte[1]{Convert.ToByte(row * 16 + clm)}); glyph += "!"; XSize size = gfx.MeasureString(glyph, font); gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height); gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading); gfx.DrawRectangle(lighter, x, y, size.Width, descent); gfx.DrawString(glyph, font, XBrushes.Black, x, y); } } }
public void DrawStats(XGraphics gfx) { XFont large = new XFont("Arial", 20); XFont small = new XFont("Arial", 12); double yOff = page_.Height * 0.11; XRect rect = new XRect(20, yOff, page_.Width - 40, page_.Height - (yOff + 20)); DrawingUtil.DrawOutlineRect(rect, gfx, cornerRadius); gfx.DrawRoundedRectangle(backgroundBrush, rect, cornerRadius); XPoint center = new XPoint(page_.Width * 0.5, page_.Height * 0.45); XImage sideLunge = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\SideLunge.png"); XImage frontLunge = XImage.FromFile(Directory.GetCurrentDirectory() + @"\Content\FrontLunge.png"); gfx.DrawString("Left Lunge", large, XBrushes.Black, new XPoint(center.X - page_.Width * 0.25, page_.Height * 0.25), XStringFormats.Center); gfx.DrawString("Right Lunge", large, XBrushes.Black, new XPoint(center.X + page_.Width * 0.25, page_.Height * 0.25), XStringFormats.Center); for (int i = 0; i < 4; i++) { Parameter param1 = userParameters_.ElementAt(dataReadStart + i); Parameter param2 = userParameters_.ElementAt(dataReadStart + i + 4); char degree = Convert.ToChar('\u00b0'); XBrush leftParamCol = XBrushes.Green; XBrush rightParamCol = XBrushes.Green; double y = (i * page_.Height * 0.15f) + page_.Height * 0.35; gfx.DrawString(param1.Name, small, XBrushes.Black, new XPoint(center.X - page_.Width * 0.25, y), XStringFormats.Center); leftParamCol = DrawingUtil.Instance.ChooseBrushColor(param1.Color); XRect infoRect = new XRect(center.X - page_.Width * 0.25 - 25, y + 20, 50, 35); DrawingUtil.DrawOutlineRect(infoRect, gfx, new XSize(10, 10)); gfx.DrawRoundedRectangle(leftParamCol, infoRect, new XSize(10, 10)); gfx.DrawString(param1.Value.ToString() + degree, small, XBrushes.Black, new XPoint(infoRect.X + 25, infoRect.Y + 17.5), XStringFormats.Center); gfx.DrawString(param2.Name, small, XBrushes.Black, new XPoint(center.X + page_.Width * 0.25, y), XStringFormats.Center); rightParamCol = DrawingUtil.Instance.ChooseBrushColor(param2.Color); infoRect = new XRect(center.X + page_.Width * 0.25 - 25, y + 20, 50, 35); DrawingUtil.DrawOutlineRect(infoRect, gfx, new XSize(10, 10)); gfx.DrawRoundedRectangle(rightParamCol, infoRect, new XSize(10, 10)); gfx.DrawString(param2.Value.ToString() + degree, small, XBrushes.Black, new XPoint(infoRect.X + 25, infoRect.Y + 17.5), XStringFormats.Center); XImage img = i > 1 ? frontLunge : sideLunge; double wRatio = (double)img.PixelWidth / (double)sideLunge.PixelHeight; XRect imgRect = new XRect(center.X - wRatio * 40, y, wRatio * 80, 80); gfx.DrawImage(img, imgRect); } }
public override void Render(ref PdfSharp.Drawing.XGraphics gfx, double _offsetLeft, double _offsetTop, double scaleX, double scaleY) { PreRender(ref gfx, offsetLeft, offsetTop, scaleX, scaleY); if (code != null && code.Length == 13) { double left = 0.0; offsetTop = _offsetTop; offsetLeft = _offsetLeft; Width *= scaleX; Height *= scaleY; font = new XFont(new Font("World", (float)Util.MillimeterToPoint((float)Math.Min(Height * 0.2, Width * 0.1) * 0.8), GraphicsUnit.World), new XPdfFontOptions(false, false)); gfx.DrawString(code[0].ToString(), font, Brushes.Black, new PointF((float)(Util.MillimeterToPoint(offsetLeft + Left + left)), (float)(Util.MillimeterToPoint(offsetTop + Top + (Height * 0.95))))); left += 4; BarWidth = (Width - left) / (3 + 6 * 7 + 5 + 6 * 7 + 3); left = DrawLeftGuard(ref gfx, code[0].ToString(), left); int first = int.Parse(code[0].ToString()); Parity par = EAN13.Parity[first]; string digit = code[1].ToString(); left = Draw(ref gfx, left, digit, EAN13.Codes[int.Parse(digit)].LhOdd); for (int i = 2; i <= 6; i++) { digit = code[i].ToString(); Pattern p = EAN13.Codes[int.Parse(digit)]; left = Draw(ref gfx, left, digit, par.IsOdd(i - 2) ? p.LhOdd : p.LhEven); } left = DrawCenterGuard(ref gfx, left); for (int i = 7; i <= 12; i++) { digit = code[i].ToString(); Pattern p = EAN13.Codes[int.Parse(digit)]; left = Draw(ref gfx, left, digit, p.Rh); } left = DrawRightGuard(ref gfx, left); Width /= scaleX; Height /= scaleY; } base.Render(ref gfx, offsetLeft, offsetTop, scaleX, scaleY); }
public void DrawBarCharts(XGraphics gfx) { XPoint backgroundPoint = new XPoint(20, page.Height * 0.585); XRect backgroundRect = new XRect(backgroundPoint.X, backgroundPoint.Y, page.Width - 40, page.Height * 0.41); gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)), backgroundRect, new XSize(40, 40)); DoubleBar ShoulderFlexionBar = new DoubleBar(userParameters["LEFT Shoulder Flexion"], userParameters["RIGHT Shoulder Flexion"], gfx); ShoulderFlexionBar.Draw(new XPoint(quaterWidth * 0.5 - 10,backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Shoulder Flexion.png")); DoubleBar hipFlexionBar = new DoubleBar(userParameters["LEFT Hip Flexion"], userParameters["RIGHT Hip Flexion"], gfx); hipFlexionBar.Draw(new XPoint(quaterWidth * 2 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Hip Flexion.png")); DoubleBar kneeFlexionBar = new DoubleBar(userParameters["LEFT Knee Flexion"], userParameters["RIGHT Knee Flexion"], gfx); kneeFlexionBar.Draw(new XPoint(quaterWidth * 3 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Knee Flexion.png")); DoubleBar ankleFlexionBar = new DoubleBar(userParameters["LEFT Ankle Flexion"], userParameters["RIGHT Ankle Flexion"], gfx); ankleFlexionBar.Draw(new XPoint(quaterWidth * 4 - (quaterWidth * 0.5) - 10, backgroundPoint.Y + 20), backgroundRect, XImage.FromFile(@"C:\Users\kevin\Desktop\PDFsharp\samples\Samples C#\Based on WPF\HelloWorld\Content\Ankle Flexion.png")); XPoint top = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.2); XPoint bottom = new XPoint(backgroundPoint.X, backgroundPoint.Y + backgroundRect.Height * 0.8); for (int i = 11; i > 0; i--) { float increment = -i * 0.1f; XPoint percentagePoint = Interpolate(top, bottom, increment); gfx.DrawString(((11 - i) * 10).ToString() + "%", new XFont("Arial", 8), XBrushes.Black, percentagePoint + new XPoint(5, 0)); gfx.DrawLine(XPens.Black, percentagePoint, percentagePoint + new XPoint(backgroundRect.Width, 0)); } }
void RenderTextAlignment(XGraphics gfx) { gfx.TranslateTransform(15, 20); XRect rect = new XRect(0, 0, 250, 140); XFont font = new XFont("Verdana", 10); XBrush brush = XBrushes.Purple; XStringFormat format = new XStringFormat(); gfx.DrawRectangle(XPens.YellowGreen, rect); gfx.DrawLine(XPens.YellowGreen, rect.Width / 2, 0, rect.Width / 2, rect.Height); gfx.DrawLine(XPens.YellowGreen, 0, rect.Height / 2, rect.Width, rect.Height / 2); gfx.DrawString("TopLeft", font, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("TopCenter", font, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("TopRight", font, brush, rect, format); format.LineAlignment = XLineAlignment.Center; format.Alignment = XStringAlignment.Near; gfx.DrawString("CenterLeft", font, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("Center", font, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("CenterRight", font, brush, rect, format); format.LineAlignment = XLineAlignment.Far; format.Alignment = XStringAlignment.Near; gfx.DrawString("BottomLeft", font, brush, rect, format); format.Alignment = XStringAlignment.Center; gfx.DrawString("BottomCenter", font, brush, rect, format); format.Alignment = XStringAlignment.Far; gfx.DrawString("BottomRight", font, brush, rect, format); }
private static void PrepareInvoiceTop(XGraphics formGfx, XGraphicsState state, string InvoiceNumber) { string Headline = "Service Invoice " + InvoiceNumber + ""; string MyName = TimeConnector.Data.Variables.SelectedContractor["CmpName"]; string Phone = TimeConnector.Data.Variables.SelectedContractorContact["ConPhone"]; string MyPhone = "Phone (" + Phone.Substring(0, 3) + ") " + Phone.Substring(4, 3) + "-" + Phone.Substring(7, 4) + ""; string MyEmail = "Email: " + TimeConnector.Data.Variables.SelectedContractorContact["ConEmail"] + ""; string MyAddress = TimeConnector.Data.Variables.SelectedContractor["CmpAddress"]; string MyCityStateZip = "" + TimeConnector.Data.Variables.SelectedContractor["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedContractor["CmpState"] + " " + TimeConnector.Data.Variables.SelectedContractor["CmpZip"] + ""; string WeekEnding = TimeConnector.Data.Variables.SelectedPaydate["WeekEnd"]; string PayDate = TimeConnector.Data.Variables.SelectedPaydate["PayDate"]; string CompanyName = TimeConnector.Data.Variables.SelectedCompany["CmpName"]; string CompanyContact = "c/o " + TimeConnector.Data.Variables.SelectedContact["ConName"] + ""; string CompanyContactPhone = "" + TimeConnector.Data.Variables.SelectedContact["ConPhone"] + ""; string CompanyContactEmail = "" + TimeConnector.Data.Variables.SelectedContact["ConEmail"] + ""; string CompanyAddress = TimeConnector.Data.Variables.SelectedCompany["CmpAddress"]; string CompanyCityStateZip = "" + TimeConnector.Data.Variables.SelectedCompany["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedCompany["CmpState"] + " " + TimeConnector.Data.Variables.SelectedCompany["CmpZip"] + ""; //----- Invoice Header XFont HeaderFont = new XFont("Imprint MT Shadow", 30, XFontStyle.Bold); string HeaderText = "I N V O I C E"; XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Near; format.LineAlignment = XLineAlignment.Near; XColor color = default(XColor); color = XColor.FromName("SteelBlue"); color.A = 0.5; XBrush brush = default(XBrush); brush = new XSolidBrush(color); XPoint point = new XPoint(410, 20); formGfx.DrawString(HeaderText, HeaderFont, brush, point, format); //..... My Company Icon state = formGfx.Save(); formGfx.DrawImage(XImage.FromFile("Images\\logo.png"), 20, 20, 65, 65); formGfx.Restore(state); //..... My Company Information DrawText(MyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.SteelBlue, 95, 20); DrawText(MyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 45); DrawText(MyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 55); DrawText(MyPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 65); DrawText(MyEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 75); XPen pen1 = new XPen(XColors.Maroon); pen1.Width = 1; //Dim pen2 As New XPen(XColors.Maroon) XPen pen2 = new XPen(XColors.SteelBlue); pen2.Width = 2; //Dim pen3 As New XPen(XColors.SteelBlue) XPen pen3 = new XPen(XColors.Maroon); pen3.Width = 1; formGfx.DrawBeziers(pen1, XPoint.ParsePoints("20,95 80,140 190,70 250,110")); DrawSignature(formGfx, 531, 696, "LightGray", 1); DrawSignature(formGfx, 530, 695, "Black", 1.5); DrawSignature(formGfx, 530, 695, "SteelBlue", 1); //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("300,100 310,110 340,90 350,100")) 'Top //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("300,100 310,110 340,90 350,100")) 'Top //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center //..... ACS Company Icon DrawText("B I L L T O :", formGfx, new XFont(PdfFont, 9, XFontStyle.Bold), XBrushes.Black, 60, 95); state = formGfx.Save(); formGfx.DrawImage(XImage.FromFile("Images\\ACSIcon.jpg"), 20, 115, 65, 65); formGfx.Restore(state); //..... ACS Company Information DrawText(CompanyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.Green, 95, 115); DrawText(CompanyContact, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 135); DrawText(CompanyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 145); DrawText(CompanyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 155); DrawText(CompanyContactPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 165); DrawText(CompanyContactEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 175); //..... Invoice Information DrawLine(formGfx, 450, 590, 80, "SteelBlue", 0.5); DrawText("Invoice #:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 71); DrawText(InvoiceNumber, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Maroon, 530, 71); DrawLine(formGfx, 450, 590, 90, "SteelBlue", 0.5); DrawText("Week Ending:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 81); DrawText(WeekEnding, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 81); DrawLine(formGfx, 450, 590, 100, "SteelBlue", 0.5); DrawText("Pay Date:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 91); DrawText(PayDate, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 91); DrawLine(formGfx, 450, 590, 110, "SteelBlue", 0.5); DrawText("Hours Worked:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 101); DrawText(TimeConnector.Data.Invoice.FinHour, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 101); DrawLine(formGfx, 450, 590, 120, "SteelBlue", 0.5); DrawText("Balance Due:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 111); DrawText(TimeConnector.Data.Invoice.FinCost, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 111); }
private static void PlotChar(string odbiorca, int c01, int r01, XGraphics formGfx, XFont font) { formGfx.DrawString(odbiorca, font, XBrushes.Navy, c01, r01, XStringFormats.TopLeft); }
private void drawName(XGraphics gfx, double _indRow, double _indCol, string _text) { // Position : 110mm * 200mm // Taille : 80mm * 10mm XFont font = new XFont("Segoe UI", 6, XFontStyle.Regular); double dx = (80 * _indCol) + 33; double dy = (113 * _indRow) + 110; gfx.DrawString(_text, font, XBrushes.DarkRed, new XRect(dx, dy, 56, 11), XStringFormats.Center); }
private static void DrawText(string text, XGraphics formGfx, XFont font, XSolidBrush color, double x, double y) { formGfx.DrawString(text, font, color, x, y, XStringFormats.TopLeft); }
void DrawFigures(XGraphics gfx, double W, double H) { /* COWARD'S TRIANGLE */ XPen pen = new XPen(XColors.Black, 1); pen.LineJoin = XLineJoin.Round; XFont T10R = new XFont("Times New Roman", 10, XFontStyle.Regular); XTextFormatter tf = new XTextFormatter(gfx); tf.Alignment = XParagraphAlignment.Center; //Triangles XPoint[] polygon = new XPoint[] { new XPoint(84, 550), new XPoint(84, 685), new XPoint(284, 685) }; gfx.DrawPolygon(pen, XBrushes.Green, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(Hx, Hy), new XPoint(Nx, Ny), new XPoint(Fx, Fy), new XPoint(284, 685) }; gfx.DrawPolygon(pen, XBrushes.Yellow, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(84, 550), new XPoint(Nx, Ny), new XPoint(Lx, Ly) }; gfx.DrawPolygon(pen, XBrushes.DarkOrange, polygon, XFillMode.Alternate); polygon = new XPoint[] { new XPoint(Hx, Hy), new XPoint(Nx, Ny), new XPoint(Lx, Ly) }; gfx.DrawPolygon(pen, XBrushes.Red, polygon, XFillMode.Alternate); //Point gfx.DrawEllipse(pen, XBrushes.White, Cx, Cy, 6, 6); //Texts XRect rect = new XRect(72, 550, 10, 10); tf.DrawString("21", T10R, XBrushes.Red, rect); rect = new XRect(72, 687, 10, 10); tf.DrawString("0", T10R, XBrushes.Red, rect); rect = new XRect(150, 687, 50, 10); tf.DrawString("Methane %", T10R, XBrushes.Red, rect); rect = new XRect(270, 687, 15, 10); tf.DrawString("100", T10R, XBrushes.Red, rect); /* ELLICOTT DIAGRAM */ rect = new XRect(297, 550, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.DarkOrange, rect); rect = new XRect(409, 550, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Red, rect); rect = new XRect(297, 625, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Green, rect); rect = new XRect(409, 625, 112, 75); gfx.DrawRectangle(XPens.Black, XBrushes.Yellow, rect); //Arrows & Texts pen.LineCap = XLineCap.Round; gfx.DrawLine(pen, 409, 625, 381, 606); gfx.DrawLine(pen, 382, 610, 381, 606); gfx.DrawLine(pen, 385, 606, 381, 606); gfx.DrawString("Lean", T10R, XBrushes.Black, 372, 600); gfx.DrawLine(pen, 409, 625, 437, 644); gfx.DrawLine(pen, 436, 640, 437, 644); gfx.DrawLine(pen, 433, 644, 437, 644); gfx.DrawString("Rich", T10R, XBrushes.Black, 430, 655); gfx.DrawLine(pen, 409, 625, 381, 644); gfx.DrawLine(pen, 382, 640, 381, 644); gfx.DrawLine(pen, 385, 644, 381, 644); gfx.DrawString("Inert", T10R, XBrushes.Black, 372, 655); //Point }
private void createSchoolName(XGraphics gfx, string _text) { // Position : 100mm * 170mm // Taille : 100mm * 10mm // Convertion 1pt = 0.35mm XFont font = new XFont("Segoe UI", 16, XFontStyle.Bold); gfx.DrawString(_text, font, XBrushes.DarkRed, new XRect(283, 481, 283, 28), XStringFormats.Center); }
private void createClassName(XGraphics gfx, string _text) { // Position : 110mm * 200mm // Taille : 80mm * 10mm XFont font = new XFont("Segoe UI", 16, XFontStyle.Bold); gfx.DrawString(_text, font, XBrushes.DarkRed, new XRect(311, 538, 226, 28), XStringFormats.Center); }
private void button_generate_Click(object sender, EventArgs e) { int yPoint = 170; PdfDocument document = new PdfDocument(); document.Info.Title = "Raport"; PdfPage page = document.AddPage(); PdfSharp.Drawing.XGraphics gfx = XGraphics.FromPdfPage(page); XFont font_bold = new XFont("Verdana", 10, XFontStyle.BoldItalic); DateTime date_from = dateTimePicker_from.Value; DateTime date_to = dateTimePicker_to.Value; var orders = db.orders.Where(o => o.deadline >= date_from && o.deadline <= date_to); if (!orders.Any()) { MessageBox.Show("There is no orders added to raport !"); } else { XFont font_regular = new XFont("Verdana", 10, XFontStyle.Bold); gfx.DrawString("Raport from: " + date_from.ToString("d") + " to: " + date_to.ToString("d"), font_regular, XBrushes.Black, new XRect(60, 80, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString("Created: ", font_regular, XBrushes.Black, new XRect(60, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString("Deadline: ", font_regular, XBrushes.Black, new XRect(160, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString("Customer: ", font_regular, XBrushes.Black, new XRect(260, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString("Employee: ", font_regular, XBrushes.Black, new XRect(360, 150, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); font_regular = new XFont("Verdana", 10, XFontStyle.Regular); foreach (order order in orders) { gfx.DrawString(order.create_timestamp.ToString("d"), font_regular, XBrushes.Black, new XRect(60, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString(order.deadline.ToString("d"), font_regular, XBrushes.Black, new XRect(160, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString(order.customer.company_name, font_regular, XBrushes.Black, new XRect(260, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawString(order.employee.firstname + " " + order.employee.lastname, font_regular, XBrushes.Black, new XRect(360, yPoint, page.Width.Point, page.Height.Point), XStringFormats.TopLeft); gfx.DrawLine(XPens.Black, 0, yPoint, 1000, yPoint); yPoint += 30; } gfx.DrawLine(XPens.Black, 0, yPoint, 1000, yPoint); SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF (*.pdf)|*.pdf", FileName = "Output.pdf" }; if (sfd.ShowDialog() == DialogResult.OK) { try { document.Save(sfd.FileName); this.Close(); } catch (Exception ex) { Console.Write(ex.Message); MessageBox.Show("You cannot generate raport unless previous one is closed !"); } } } }
public static void Test(PdfSharp.Drawing.XGraphics gfx) { XRect rect; XPen pen; double x = 50, y = 100; XFont fontH1 = new XFont("Times", 18, XFontStyle.Bold); XFont font = new XFont("Times", 12); XFont fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic); double ls = font.GetHeight(gfx); // Draw some text gfx.DrawString("Create PDF on the fly with PDFsharp", fontH1, XBrushes.Black, x, x); gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " + "text and images on different targets.", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("The object used for drawing is the XGraphics object.", font, XBrushes.Black, x, y); y += 2 * ls; // Draw an arc pen = new XPen(XColors.Red, 4); pen.DashStyle = XDashStyle.Dash; gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120); // Draw a star XGraphicsState gs = gfx.Save(); gfx.TranslateTransform(x + 140, y + 30); for (int idx = 0; idx < 360; idx += 10) { gfx.RotateTransform(10); gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0); } gfx.Restore(gs); // Draw a rounded rectangle rect = new XRect(x + 230, y, 100, 60); pen = new XPen(XColors.DarkBlue, 2.5); XColor color1 = XColor.FromKnownColor(System.Drawing.KnownColor.DarkBlue); XColor color2 = XColors.Red; XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10)); // Draw a pie pen = new XPen(XColors.DarkOrange, 1.5); pen.DashStyle = XDashStyle.Dot; gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135); // Draw some more text y += 60 + 2 * ls; gfx.DrawString("With XGraphics you can draw on a PDF page as well as " + "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y); y += ls * 1.1; gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y); x += 10; y += ls * 1.1; gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw above or beneath of the content of an existing PDF page", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y); y += ls; gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y); x -= 10; y += ls * 1.1; gfx.DrawString("You can also import an existing PDF page and use it like " + "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y); y += ls * 1.1 * 2; gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " + "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; gfx.DrawString("Below this text is a PDF form that will be visible when " + "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y); y += ls * 1.1; XGraphicsState state = gfx.Save(); XRect rcImage = new XRect(100, y, 100, 100 * System.Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
public static void BeginBox(XGraphics gfx, int number, string title, double borderWidth, double borderHeight, XColor shadowColor, XColor backColor, XColor backColor2, XPen borderPen) { const int dEllipse = 15; XRect rect = new XRect(0, 20, 300, 200); if (number % 2 == 0) rect.X = 300 - 5; rect.Y = 40 + ((number - 1) / 2) * (200 - 5); rect.Inflate(-10, -10); XRect rect2 = rect; rect2.Offset(borderWidth, borderHeight); gfx.DrawRoundedRectangle(new XSolidBrush(shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8)); XLinearGradientBrush brush = new XLinearGradientBrush(rect, backColor, backColor2, XLinearGradientMode.Vertical); gfx.DrawRoundedRectangle(borderPen, brush, rect, new XSize(dEllipse, dEllipse)); rect.Inflate(-5, -5); XFont font = new XFont("Verdana", 12, XFontStyle.Regular); gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter); rect.Inflate(-10, -5); rect.Y += 20; rect.Height -= 20; state = gfx.Save(); gfx.TranslateTransform(rect.X, rect.Y); }
/// <summary> /// Demonstrates serveral bar code types. /// </summary> public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); XFont font = new XFont("Verdana", 14, XFontStyle.Bold); string info = "DataMatrix is a fake in the Open Source version!"; XSize size = gfx.MeasureString(info, font); gfx.DrawString(info, font, XBrushes.Firebrick, (600 - size.Width) / 2, 50); //Graphics grfx = gfx.Internals.Graphics; CodeDataMatrix dm = new CodeDataMatrix("test", 26); dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 100)); dm = new CodeDataMatrix("test", 12, 12); dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 100)); dm = new CodeDataMatrix("test", 16, 48); dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(18)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 100)); dm = new CodeDataMatrix("0123456789", 52); dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 300)); dm = new CodeDataMatrix("0123456789", 12, 26); dm.Direction = CodeDirection.TopToBottom; dm.Size = new XSize(XUnit.FromMillimeter(14), XUnit.FromMillimeter(7)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 300)); dm = new CodeDataMatrix("0123456789", 96); dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 300)); dm = new CodeDataMatrix("www.empira.de", 20); dm.Direction = CodeDirection.BottomToTop; dm.Size = new XSize(XUnit.FromMillimeter(7), XUnit.FromMillimeter(7)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 500)); dm = new CodeDataMatrix("www.empira.de", 144, 144, 2); dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(50)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 500)); dm = new CodeDataMatrix("www.empira.de", 88); dm.Direction = CodeDirection.RightToLeft; dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15)); gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 500)); }
private static void RenderWord(string word, XGraphics gfx, XRect rect, int fontsize, string color = null) { XFont font = new XFont("Garamond", fontsize, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode)); XBrush brush; if(string.IsNullOrEmpty(color)) brush = XBrushes.Black; else { XColor xcolor = XColor.FromArgb(ColorTranslator.FromHtml("#" + color)); brush = new XSolidBrush(xcolor); } XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Center; format.LineAlignment = XLineAlignment.Center; gfx.DrawString(word.ToLower(), font, brush, rect, format); }