C# PDF Drawing Library
How to draw, add a start shape to PDF file using C#
C# Demo Code to create, draw, add a start graph to pdf document
In this C# tutorial, you learn how to draw, add star shape to PDF file using C# in ASP.NET WebForm, MVC, Windows applications.
- Define a start with lines in REPath object
- Customize the start shape with line color, line width
Draw a start on PDF context in C#.NET
In C# code below, you learn how to draw, add a start shape to PDF file using C#
- Define a PDFContext with specified width and height, where you can draw line shapes
- Define a REPath object, and use REPath.AddLine() to draw 5 lines, which will group a star shape
- Utilize method PDFContext.DrawPath() to draw the star with line color and line width on PDF context
- 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 a star
REPath path = new REPath();
path.AddLine(100, 70, 300, 70);
path.AddLine(300, 70, 130, 170);
path.AddLine(130, 170, 200, 10);
path.AddLine(200, 10, 270, 170);
path.AddLine(270, 170, 100, 70);
path.CloseAllPath();
ctx.DrawPath(new REPen(new REColor(255, 0, 0), 5F), path);
Figure figure = new Figure(ctx);
...
Add context to PDF document using C#
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 a start on PDF using C#: