IronPDF How-Tos Draw Line & Rectangle How to Draw Lines and Rectangles on PDFs Chaknith Bin Updated:July 28, 2025 Drawing lines and rectangles onto a PDF document refers to the process of adding geometric shapes, specifically lines and rectangles, to the content of a PDF file. This is often done programmatically using a programming language like C# or VB.NET and a library like IronPDF. When you draw a line, you create a visible line segment with specified starting and ending points. Similarly, when you draw a rectangle, you define a four-sided shape with specified dimensions and positions. Get started with IronPDF Start using IronPDF in your project today with a free trial. First Step: Start for Free How to Draw Lines and Rectangles on PDFs in C# Download IronPDF C# Library from NuGet Import the target PDF document or render it from HTML Use the DrawLine Method for Adding Lines to PDFs Use the DrawRectangle Method for Adding Rectangles Export the edited PDF document Draw Line Example By utilizing the DrawLine method available for the PdfDocument object, you can add lines to an existing PDF. Using the Color class offered by IronDrawing API Documentation opens up the possibility to apply a line with a color from a HEX color code. :path=/static-assets/pdf/content-code-examples/how-to/draw-line-and-rectangle-draw-line.cs using IronPdf; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>"); // Configure the required parameters int pageIndex = 0; var start = new IronSoftware.Drawing.PointF(200,150); var end = new IronSoftware.Drawing.PointF(1000,150); int width = 10; var color = new IronSoftware.Drawing.Color("#000000"); // Draw line on PDF pdf.DrawLine(pageIndex, start, end, width, color); pdf.SaveAs("drawLine.pdf"); Imports IronPdf Private renderer As New ChromePdfRenderer() Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>") ' Configure the required parameters Private pageIndex As Integer = 0 Private start = New IronSoftware.Drawing.PointF(200,150) Private [end] = New IronSoftware.Drawing.PointF(1000,150) Private width As Integer = 10 Private color = New IronSoftware.Drawing.Color("#000000") ' Draw line on PDF pdf.DrawLine(pageIndex, start, [end], width, color) pdf.SaveAs("drawLine.pdf") $vbLabelText $csharpLabel Output PDF Draw Rectangle Example To add rectangles to PDFs, use the DrawRectangle method. Once the PDF document is opened or rendered, this method is available for the PdfDocument object. Easily configure the coordinates, width, and height for the rectangle with the RectangleF class offered by IronDrawing API Documentation. :path=/static-assets/pdf/content-code-examples/how-to/draw-line-and-rectangle-draw-rectangle.cs using IronPdf; ChromePdfRenderer renderer = new ChromePdfRenderer(); PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>testing</h1>"); // Configure the required parameters int pageIndex = 0; var rectangle = new IronSoftware.Drawing.RectangleF(200, 100, 1000, 100); var lineColor = new IronSoftware.Drawing.Color("#000000"); var fillColor = new IronSoftware.Drawing.Color("#32AB90"); int lineWidth = 5; // Draw rectangle on PDF pdf.DrawRectangle(pageIndex, rectangle, lineColor, fillColor, lineWidth); pdf.SaveAs("drawRectangle.pdf"); Imports IronPdf Private renderer As New ChromePdfRenderer() Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>testing</h1>") ' Configure the required parameters Private pageIndex As Integer = 0 Private rectangle = New IronSoftware.Drawing.RectangleF(200, 100, 1000, 100) Private lineColor = New IronSoftware.Drawing.Color("#000000") Private fillColor = New IronSoftware.Drawing.Color("#32AB90") Private lineWidth As Integer = 5 ' Draw rectangle on PDF pdf.DrawRectangle(pageIndex, rectangle, lineColor, fillColor, lineWidth) pdf.SaveAs("drawRectangle.pdf") $vbLabelText $csharpLabel Output PDF Frequently Asked Questions How to draw lines on PDFs using C#? To draw lines on PDFs using C#, use the DrawLine method of the PdfDocument object in IronPDF. This method allows you to specify the line's starting and ending points, as well as apply colors using HEX codes with the IronDrawing API. What are the steps to draw rectangles on PDF documents with C#? First, download the IronPDF library from NuGet. Then, import or render the target PDF document. Use the DrawRectangle method to add rectangles by defining coordinates, width, and height with the RectangleF class. Finally, export the edited PDF document. Can I use VB.NET to draw shapes on a PDF? Yes, you can use VB.NET to draw shapes on a PDF. IronPDF supports both C# and VB.NET, allowing you to utilize methods like DrawLine and DrawRectangle to add lines and rectangles to your PDF documents. How do you apply color to lines in a PDF using C#? In C#, you can apply color to lines in a PDF using the Color class in combination with the ColorTranslator.FromHtml method to specify a HEX color code. This is used within the DrawLine method of IronPDF. Where can I find detailed documentation for drawing lines and rectangles? Detailed documentation for drawing lines and rectangles using IronPDF can be found in the [IronDrawing API Documentation](https://ironsoftware.com/open-source/csharp/drawing/docs/). It provides comprehensive guides and examples for utilizing drawing functionalities. Is it possible to edit an existing PDF to add geometric shapes with C#? Yes, it is possible to edit an existing PDF to add geometric shapes with C#. Using IronPDF, you can render a PDF and use methods like DrawLine and DrawRectangle to integrate lines and rectangles programmatically. How can you export a PDF after adding lines and rectangles? After adding lines and rectangles to a PDF using IronPDF, you can export the modified document by using the SaveAs method of the PdfDocument object, specifying the desired file output path. What are the prerequisites for using IronPDF in a C# project? To use IronPDF in a C# project, you need to download and install the IronPDF library from NuGet. Ensure your development environment supports .NET languages like C# or VB.NET. Chaknith Bin Chat with engineering team now Software Engineer Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience. Ready to Get Started? Free NuGet Download Total downloads: 15,030,178 View Licenses