PDF Mosaic: How to create gray color space in PDF and draw graphics elements


Home       Features       Download       Tutorial       Version History       License       Source Code

 

This sample shows how to create gray color space and then create and use a color with that 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);
        }
    }
}

 

Visial Basic.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

 


Home       Features       Download       Tutorial       Version History       License       Source Code