How To Create Gray Color Space in PDF and Draw Graphics Elements using PDF .NET Mosaic

This sample shows how to create an gray color space and then create and use a color with that color space.

Gray color space

C# :

using PDFMosaic;
using System.Drawing;
using System;

namespace GrayColorSpace
{
  class GrayColorSpace
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
      PDFCanvas canvas = document.Pages[0].Canvas;

      Random rnd = new Random();
      
      for(int i = 0; i < 5; ++i)
      {
        PDFColorGray colorGray = new PDFColorGray((byte)rnd.Next(255));
        PDFSolidBrush brushGray = new PDFSolidBrush(colorGray);
        
        canvas.DrawEllipse(brushGray, 10 + 20*i, 10 + 20*i, 70, 100);
      }

      document.Save("GrayColorSpace.pdf", true);
    }
  }
}

VB.NET :

Imports PDFMosaic
Imports System.Drawing
Imports System

Module ColorProfiles
  Sub Main()
    Dim document As PDFDocument = New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
    Dim canvas As PDFCanvas = document.Pages(0).Canvas

    Dim rnd As New Random()

    Dim i As Integer
    For i = 0 To 4
    Dim colorGray As PDFColorGray = New PDFColorGray(rnd.Next(255))
    Dim brushGray As PDFSolidBrush = New PDFSolidBrush(colorGray)
    
    canvas.DrawEllipse(brushGray, 10 + i*20, 100 + i*20, 70, 100)
    Next i

    document.Save("ColorProfiles.pdf", True)
  End Sub
End Module