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

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

CMYK color space

C# :

using PDFMosaic;
using System.Drawing;
using System;

namespace CMYKColorSpace
{
class CMYKColorSpace
{
 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)
  {
  PDFColorCMYK colorCMYK = new PDFColorCMYK((byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255));
  PDFSolidBrush brushCMYK = new PDFSolidBrush(colorCMYK);
  
  canvas.DrawRoundedRectangle(brushCMYK, 10 + 20*i, 10 + 20*i, 70, 100, 10);
  }

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

VB.NET :

Imports PDFMosaic
Imports System.Drawing
Imports System

Module CMYKColorSpace
 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 colorCMYK As PDFColorCMYK = New PDFColorCMYK(rnd.Next(255), rnd.Next(255), rnd.Next(255), rnd.Next(255))
  Dim brushCMYK As PDFSolidBrush = New PDFSolidBrush(colorCMYK)
  
  canvas.DrawRoundedRectangle(brushCMYK, 10 + i*20, 100 + i*20, 70, 100, 10)
  Next i

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