ByteScout PDF SDK - C# - Draw Rectangles in PDF - ByteScout

ByteScout PDF SDK – C# – Draw Rectangles in PDF

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Draw Rectangles in PDF

How to draw rectangles in PDF in C# and ByteScout PDF SDK

Write code in C# to draw rectangles in PDF with this step-by-step tutorial

We made thousands of pre-made source code pieces for easy implementation in your own programming projects. ByteScout PDF SDK is the pdf library that can create, update and modify PDF files. Supports text with fonts and style selections, layers, form fields, drawing lines and objects, automatic tables, images. Can be used to create and fill pdf forms. It can draw rectangles in PDF in C#.

The SDK samples like this one below explain how to quickly make your application do draw rectangles in PDF in C# with the help of ByteScout PDF SDK. Follow the instructions from the scratch to work and copy the C# code. Use of ByteScout PDF SDK in C# is also explained in the documentation included along with the product.

Download free trial version of ByteScout PDF SDK from our website with this and other source code samples for C#.

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

Program.cs
      
using System.Diagnostics; using System.Drawing; using Bytescout.PDF; using Brush = Bytescout.PDF.Brush; using Pen = Bytescout.PDF.Pen; using SolidBrush = Bytescout.PDF.SolidBrush; namespace Rectangles { /// <summary> /// This example demonstrates how to draw rectangles. /// </summary> class Program { static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); Canvas canvas = page.Canvas; // Prepare pens and brushes Pen borderPen = new SolidPen(new ColorGray(128), 2f); Brush brush1 = new SolidBrush(new ColorRGB(255, 0, 0)); Brush brush2 = new SolidBrush(new ColorRGB(0, 255, 255)); // Draw transparent rectangle with border only canvas.DrawRectangle(borderPen, 100, 100, 100, 50); // Draw rounded rectangle with broder and filling canvas.DrawRoundedRectangle(borderPen, brush1, 250, 100, 100, 50, 10); // Draw rectangle as polygon canvas.DrawPolygon(borderPen, brush2, new PointF[] { new PointF(400, 100), new PointF(500, 100), new PointF(500, 150), new PointF(400, 150) }); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); } } }

Try ByteScout PDF SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

VIDEO

ON-PREMISE VERSION INFORMATION

Get 60 Day Free Trial or Visit ByteScout PDF SDK Home Page

Explore ByteScout PDF SDK Documentation

Get ByteScout PDF SDK Free Training

WEB API

Get Your Free API Key

Explore Web API Documentation

Tutorials:

prev
next