Adding Shapes to PDFs
Adding basic shapes such as circles, rectangles, lines and paths to a PDF document is straightforward using DynamicPDF Core Suite for .NET. The following C# examples illustrate.
Watch the Video
How to Add Circle to PDF
The following steps and C# sample code illustrate adding a Circle
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a Circle to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
Circle
object by specifying the parameters. - Add the
Circle
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add( page );
Circle circle1 = new Circle(100, 100, 50, 100, Grayscale.Black, RgbColor.OrangeRed, 2, LineStyle.Solid);
page.Elements.Add(circle1);
document.Draw("Output.pdf");
How to Add Rectangle to PDF
The following steps and C# sample code illustrate adding a Rectangle
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a Rectangle to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
Rectangle
object by specifying the parameters. - Add the
Rectangle
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Rectangle rectangle = new Rectangle(10, 10, 400, 300, RgbColor.Red, RgbColor.Navy);
page.Elements.Add(rectangle);
document.Draw("Output.pdf");
How to Add Line to PDF
The following steps and C# sample code illustrate adding a Line
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a Circle to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
Line
object by specifying the parameters. - Add the
Line
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new();
Page page = new Page();
document.Pages.Add(page);
Line line = new(150, 0, 150, 300);
line.Color = RgbColor.Navy;
line.Width = 10;
line.Cap = LineCap.Butt;
page.Elements.Add(line);
document.Draw("Output.pdf");
How to Add Path to PDF
The following steps and C# sample code illustrates adding a Path
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding Path to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to theDocument
instance. - Create a
Path
object by specifying the parameters. - Add four sub-paths to the
Path
instance (CurveSubPath, LineSubPath, CurveToSubPath and CurveFromSubPath). - Add the
Path
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add( page );
Path path = new Path( 50, 150, RgbColor.Blue, RgbColor.Yellow, 3, LineStyle.Solid, true );
path.SubPaths.Add( new CurveSubPath( 50, 400, 300, 150, -200, 400 ) );
path.SubPaths.Add( new LineSubPath( 300, 400 ) );
path.SubPaths.Add( new CurveToSubPath( 300, 150, 50, 300 ) );
path.SubPaths.Add( new CurveFromSubPath( 150, 100, 200, -100 ) );
page.Elements.Add( path );
document.Draw(@"Output.pdf");
GitHub Project
An example project is available on GitHub (examples.dynamicpdf-core-suite-dotnet-core). Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This specific example discussed on this page are all contained in following classes on GitHub
- C# - AddShapeExample.cs
- VB.NET - AddShapeExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing the product.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Shapes
- Refer to the Vector Graphics documentation topic, or
- Chapter 5, Vector Graphics, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX