How To Draw Rectangles In PDF Documents Using PDF Mosaic .NET

This sample shows how to draw rectangles on a canvas using semi-transparentcolors.
Use PDFPen.Opacity and/or PDFSolidBrush.Opacity properties tomake current pen or brush color semi-transparent. Opacity valueranges from 0 (fully transparent) to 100 (fully opaque).

Rectangles

 

using PDFMosaic;
using System.Drawing;
using System;

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

            PDFSolidBrush brush = new PDFSolidBrush(new PDFColorCMYK(123, 255, 0, 50));
            brush.Opacity = 0;
            for (int i = 0; i < 10; ++i)
            {
                canvas.DrawRectangle(brush, i * 10, i * 10, i * 10 + 20, i * 10 + 20);
                brush.Opacity = i * 10 + 10;
            }

            brush.Opacity = 0;
            for (int i = 0; i < 10; ++i)
            {
                canvas.DrawRoundedRectangle(brush, 200 + i * 10, i * 10, i * 10 + 220, i * 10 + 20, i * 2);
                brush.Opacity = i * 10 + 10;
            }

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