|
Using C# PDF Drawing Library
How to draw, add an ellipse shape to PDF file using C# in ASP.NET, Windows app
C# Demo Code to create, draw, add an ellipse graph to pdf document
In this C# tutorial, you learn how to draw, add new ellipses to PDF file using C# in ASP.NET Windows applications.
- Draw new ellipses on PDF file
- Customize ellipses with line color, position, fill color
Draw ellipse on PDF context using C#
In C# code below, you learn how to draw, add three new ellipses to PDF file using C#
- Define a PDFContext with specified width and height, where you can draw ellipses
- Utilize method PDFContext.FillEllipse() to draw ellipse with fill color
- Utilize method PDFContext.DrawEllipse() to draw ellipse without fill color
- Add the PDF context to the PDF document
...
PDFContext ctx = new PDFContext();
// set figure size: width 600 pixels; height 200 pixels
ctx.SetWidth(new RELength(600, Units.PX));
ctx.SetHeight(new RELength(200, Units.PX));
// draw and fill 3 ellipses
ctx.FillEllipse(new RESolidBrush(new REColor(255, 0, 0)), 150, 10, 180, 80);
ctx.DrawEllipse(new REPen(new REColor(0, 0, 0)), 150, 10, 180, 80);
ctx.FillEllipse(new RESolidBrush(new REColor(0, 255, 0)), 300, 10, 150, 70);
ctx.DrawEllipse(new REPen(new REColor(0, 0, 0), 3F), 300, 10, 150, 70);
ctx.DrawEllipse(new REPen(new REColor(0, 0, 255), 5F), 240, 75, 120, 100);
Figure figure = new Figure(ctx);
document.Add(figure);
...
Add context to PDF document
String outputFilePath = Program.RootPath + "\\" + "Sample25.pdf";
Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);
// open document
document.Open();
// create Figure
PDFContext ctx = new PDFContext();
...
...
Figure figure = new Figure(ctx);
document.Add(figure);
// close document and save to the output file
document.Close();
Let's see the result of adding ellipses on PDF using C#:
|