public Result ExportToPdf(Customer customer, Fortune fortune) { try { PdfDocument doc = new PdfDocument(); doc.Info.Title = "Kundenreport - " + customer.Name; PdfPage page = doc.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont fontBold = new XFont("Times New Roman", 20, XFontStyle.Bold); XFont fontNormal = new XFont("Times New Roman", 18, XFontStyle.Regular); gfx.DrawString("Kundenreport:", fontBold, XBrushes.Black, new XRect(50, 10, 600, 25), XStringFormats.TopLeft); gfx.DrawString("Name: " + customer.Name, fontNormal, XBrushes.Black, new XRect(50, 50, 600, 25), XStringFormats.TopLeft); gfx.DrawString("Email: " + customer.Mail, fontNormal, XBrushes.Black, new XRect(50, 75, 600, 25), XStringFormats.TopLeft); gfx.DrawString("Telefonnummer: " + customer.PhoneNumber, fontNormal, XBrushes.Black, new XRect(50, 100, 600, 25), XStringFormats.TopLeft); XPen pen = new XPen(XColors.DarkBlue, 2.5); gfx.DrawPie(pen, XBrushes.Gold, 10, 0, 100, 90, -120, 75); gfx.DrawPie(pen, XBrushes.Gold, 10, 50, 100, 90, 80, 70); gfx.DrawPie(pen, XBrushes.Gold, 150, 80, 60, 60, 35, 290); const string filename = "Kundenreport.pdf"; doc.Save(filename); return(new Result(status: Status.Success)); } catch (Exception e) { return(new Result(status: Status.Error)); } }
void RenderPies(XGraphics gfx) { gfx.TranslateTransform(15, 20); XPen pen = new XPen(XColors.DarkBlue, 2.5); gfx.DrawPie(pen, 10, 0, 100, 90, -120, 75); gfx.DrawPie(XBrushes.Gold, 130, 0, 100, 90, -160, 150); gfx.DrawPie(pen, XBrushes.Gold, 10, 50, 100, 90, 80, 70); gfx.DrawPie(pen, XBrushes.Gold, 150, 80, 60, 60, 35, 290); }
private void DrawPie(XGraphics gfx, int number) { base.BeginBox(gfx, number, "DrawPie"); XPen pen = new XPen(XColors.DarkBlue, 2.5); gfx.DrawPie(pen, 10, 0, 100, 90, -120, 75); gfx.DrawPie(XBrushes.Gold, 130, 0, 100, 90, -160, 150); gfx.DrawPie(pen, XBrushes.Gold, 10, 50, 100, 90, 80, 70); gfx.DrawPie(pen, XBrushes.Gold, 150, 80, 60, 60, 35, 290); base.EndBox(gfx); }
private void DrawHeader(XGraphics gfx) { gfx.DrawLine(XPens.Orange, 50, 50, 250, 50); XRect rcImage = new XRect(50, 35, 100, 15); gfx.DrawRectangle(XBrushes.Orange, rcImage); gfx.DrawString("APPLICANT", FontUtility.HeaderTitle, XBrushes.White, rcImage, XStringFormats.Center); gfx.DrawString("John Doe", FontUtility.HeaderContentBig, XBrushes.Black, new XRect(50, 62, 100, 0)); gfx.DrawString("*****@*****.**", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(50, 75, 100, 0)); gfx.DrawString("802-123-4567", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(50, 85, 100, 0)); gfx.DrawLine(XPens.DarkBlue, 280, 50, 500, 50); XRect rcImage2 = new XRect(280, 35, 100, 15); gfx.DrawRectangle(XBrushes.DarkBlue, rcImage2); gfx.DrawString("APPLYING FOR", FontUtility.HeaderTitle, XBrushes.White, rcImage2, XStringFormats.Center); gfx.DrawString("Cyber Reverse Engineer", FontUtility.HeaderContentBig, XBrushes.Black, new XRect(280, 62, 100, 0)); gfx.DrawString("iNovex Information Systems Savage, MD", FontUtility.HeaderContentNormal, XBrushes.Black, new XRect(280, 75, 100, 0)); XPen pen = new XPen(XColors.Orange, 1); pen.DashStyle = XDashStyle.Solid; gfx.DrawPie(pen, XBrushes.OrangeRed, 545, 5, 60, 60, 90, 90); gfx.DrawString("18", FontUtility.HeaderTitle, XBrushes.White, new XRect(555, 50, 50, 0)); }
/// <summary> /// Draws the content of the pie plot area. /// </summary> internal override void Draw() { ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo; XRect plotAreaRect = cri.plotAreaRendererInfo.Rect; if (plotAreaRect.IsEmpty) { return; } if (cri.seriesRendererInfos.Length == 0) { return; } XGraphics gfx = _rendererParms.Graphics; XGraphicsState state = gfx.Save(); // Draw sectors. SeriesRendererInfo sri = cri.seriesRendererInfos[0]; foreach (SectorRendererInfo sector in sri._pointRendererInfos) { if (!double.IsNaN(sector.StartAngle) && !double.IsNaN(sector.SweepAngle)) { gfx.DrawPie(sector.FillFormat, sector.Rect, sector.StartAngle, sector.SweepAngle); } } // Draw border of the sectors. foreach (SectorRendererInfo sector in sri._pointRendererInfos) { if (!double.IsNaN(sector.StartAngle) && !double.IsNaN(sector.SweepAngle)) { gfx.DrawPie(sector.LineFormat, sector.Rect, sector.StartAngle, sector.SweepAngle); } } gfx.Restore(state); }
/// <summary> /// Renders the content of the page. /// </summary> public void Render(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(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 * Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); }
public void Pie2(XGraphics gfx, XRect rect, double startAngle, double sweepAngle) { Box(gfx, rect, startAngle, sweepAngle); gfx.DrawPie(properties.Pen2.Pen, properties.Brush2.Brush, rect, startAngle, sweepAngle); }
public void Shapes() { string filename = "Shapes.pdf"; PdfDocument document = new PdfDocument(); //document.Options.ColorMode = PdfColorMode.Cmyk; // Set version to PDF 1.4 (Acrobat 5) because we use transparency. //if (document.Version < 14) // document.Version = 14; //PdfPage page = document.Pages[0]; //// Get an XGraphics object for drawing beneath the existing content //XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append); LayoutHelper helper = new LayoutHelper(document, XUnit.FromCentimeter(2.5), XUnit.FromCentimeter(29.7 - 2.5)); XUnit left = XUnit.FromCentimeter(2.5); helper.CreatePage(); XGraphics gfx = helper.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(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 * Math.Sqrt(2)); gfx.DrawRectangle(XBrushes.Snow, rcImage); //gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage); gfx.Restore(state); document.Save(filename); LaunchPdf(filename); }