How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

Using C# PDF Drawing Library
How to draw, add a curve shape to PDF file using C#

C# Demo Code to create, draw, add a curve graph to pdf document

In this C# tutorial, you learn how to draw, add new curves to PDF file using C# in ASP.NET WebForm, MVC, Windows applications.

  • Define curves on a REPath object
  • Customize curves with color, shape

Draw a curves on PDF context using C# code

In C# code below, you learn how to draw, add curves (heart shape) to PDF file using C#

  • Define a PDFContext with specified width and height, where you can draw curve shapes
  • Utilize method REPath.AddBezier() to draw curves
  • Utilize method PDFContext.FillPath() to paint colors inside the curves on PDF context
  • Utilize method PDFContext.DrawPath() to draw the curves on PDF context
  • Add the PDF context to the PDF document

PDFContext ctx = new PDFContext();
//  set figure size: width 600 pixels; height 300 pixels
ctx.SetWidth(new RELength(600, Units.PX));
ctx.SetHeight(new RELength(300, Units.PX));
//  draw a heart
REPath path = new REPath();
path.AddBezier(200, 110, 200, 70, 270, 60, 300, 110);
path.AddBezier(300, 110, 330, 60, 400, 70, 400, 110);
path.AddBezier(400, 110, 400, 150, 380, 200, 300, 250);
path.AddBezier(300, 250, 220, 200, 200, 150, 200, 110);
ctx.FillPath(new RESolidBrush(new REColor(255, 0, 0)), path);
ctx.DrawPath(new REPen(new REColor(224, 224, 0), 3F), path);
Figure figure = new Figure(ctx);

Add context to PDF document in C#

String outputFilePath = Program.RootPath + "\\" + "Sample25.pdf";

Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);
//  open document
//  create Figure
PDFContext ctx = new PDFContext();
Figure figure = new Figure(ctx);
//  close document and save to the output file

Let's see the result of adding a curve on PDF using C#: