This sample shows how to use colors.

Docotic.Pdf library supports Gray, RGB and CMYK colors. Corresponding classes are PdfGrayColor, PdfRgbColor and PdfCmykColor.

Use PdfCanvas.Pen.Color and PdfCanvas.Brush.Color properties to set color of a pen or a brush to be used on canvas. Pens are used to stroke lines, brushes are used to fill areas and shapes.

C#
using System.Diagnostics;
using System.Drawing;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class Colors
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "Colors.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                canvas.Brush.Color = new PdfRgbColor(255, 0, 0);
                canvas.Pen.Color = new PdfRgbColor(0, 255, 255);
                canvas.Pen.Width = 3;

                canvas.DrawEllipse(new RectangleF(10, 50, 200, 100), PdfDrawMode.FillAndStroke);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics
Imports System.Drawing

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class Colors
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "Colors.pdf"

            Using pdf As New PdfDocument()
                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas

                canvas.Brush.Color = New PdfRgbColor(255, 0, 0)
                canvas.Pen.Color = New PdfRgbColor(0, 255, 255)
                canvas.Pen.Width = 3

                canvas.DrawEllipse(New RectangleF(10, 50, 200, 100), PdfDrawMode.FillAndStroke)

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace