How To Create RGB Color Space in PDF and Draw Rectangles Using PDF .NET Mosaic

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

RGB Color Space

C# :

using PDFMosaic;
using System.Drawing;
using System;

namespace RGBColorSpace
{
 class RGBColorSpace
 {
  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)
   {
    PDFColorRGB colorRGB = new PDFColorRGB((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
    PDFSolidBrush brushRGB = new PDFSolidBrush(colorRGB);
    
    canvas.DrawRectangle(brushRGB, 10 + 20*i, 10 + 20*i, 70, 100);
   }

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

VB.NET :

Imports PDFMosaic
Imports System.Drawing
Imports System

Module RGBColorSpace
  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 colorRGB As PDFColorRGB = New PDFColorRGB(rnd.Next(255), rnd.Next(255), rnd.Next(255))
    Dim brushRGB As PDFSolidBrush = New PDFSolidBrush(colorRGB)
    
    canvas.DrawRectangle(brushRGB, 10 + i*20, 100 + i*20, 70, 100)
    Next i

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