How to Draw Lines and Rectangles on PDFs

In this tutorial, we explore how to draw lines and rectangles on PDF documents using Iron PDF within a C# console application. The process begins with installing Iron PDF through NuGet Package Manager and importing relevant namespaces such as IronPDF for PDF manipulation, IronSoftware.Drawing for drawing capabilities, and System.IO for file handling. The tutorial emphasizes setting up a license key to ensure proper usage permissions.

Next, we create a ChromePdfRenderer instance to convert HTML content into a PDF. The example uses a simple HTML string with a header tag to generate a basic PDF document. To draw a line, we define parameters including page index, start and end points, width, and color. The drawLine method is used to add a horizontal black line to the document, enhancing its layout.

For drawing rectangles, we configure parameters like position, size, border color, fill color, and border width. The drawRectangle method is then used to add a green rectangle with a black border to the PDF, enriching its graphical elements. Finally, the modified PDF is saved to a specified location, allowing easy access and viewing.

The tutorial concludes by executing the program, showcasing the PDF with a header, black line, and green rectangle. It underscores the simplicity of integrating shapes into PDFs using Iron PDF and encourages trying the trial subscription available on their website.

Further Reading: How to Draw Lines and Rectangles on PDFs

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Draw Text and Bitmap on PDFs
NEXT >
How to Convert DOCX to PDF Using C#