menu

Document Processing

PdfColor Class - C# PDF Library API Reference | Syncfusion

    Show / Hide Table of Contents

    PdfColor Class

    Implements structures and routines working with color.

    Inheritance
    System.Object
    PdfColor
    Namespace: Syncfusion.Pdf.Graphics
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public sealed class PdfColor : ValueType
    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(Color.Red);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(Color.Red)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Constructors

    PdfColor(PdfColor)

    Initializes a new instance of the PdfColor class with source color

    Declaration
    public PdfColor(PdfColor color)
    Parameters
    Type Name Description
    PdfColor color

    Source color object.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(new PdfColor(Color.Green));
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(New PdfColor(Color.Green))
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfColor(Byte, Byte, Byte)

    Initializes a new instance of the PdfColor class with Red,Green and Blue values.

    Declaration
    public PdfColor(byte red, byte green, byte blue)
    Parameters
    Type Name Description
    System.Byte red

    Red channel value.

    System.Byte green

    Green channel value.

    System.Byte blue

    Blue channel value.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(200, 120, 80);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(200, 120, 80)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfColor(Color)

    Initializes a new instance of the PdfColor class with System.Drawing.Color object

    Declaration
    public PdfColor(Color color)
    Parameters
    Type Name Description
    System.Drawing.Color color

    Source color object.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(Color.Red);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(Color.Red)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfColor(Single)

    Initializes a new instance of the PdfColor class with gray value

    Declaration
    public PdfColor(float gray)
    Parameters
    Type Name Description
    System.Single gray

    Gray value.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(0.5f);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(0.5F)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfColor(Single, Single, Single, Single)

    Initializes a new instance of the PdfColor class with Cyan,Magenta,Yellow and Black channels.

    Declaration
    public PdfColor(float cyan, float magenta, float yellow, float black)
    Parameters
    Type Name Description
    System.Single cyan

    Cyan channel value.

    System.Single magenta

    Magenta channel value.

    System.Single yellow

    Yellow channel value.

    System.Single black

    Black channel value.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = new PdfColor(200, 120, 80, 40);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As New PdfColor(200, 120, 80, 40)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Properties

    B

    Gets or sets Blue channel value.

    Declaration
    public byte B { get; set; }
    Property Value
    Type Description
    System.Byte

    The B.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("SlateBlue");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the blue channel value.   
    string text = "The blue channel value is " + pdfColor.B;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("SlateBlue")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the blue channel value.   
    Dim text As String = "The blue channel value is " + pdfColor.B
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Blue

    Gets the blue color

    Declaration
    public float Blue { get; }
    Property Value
    Type
    System.Single
    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("Blue");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the blue color value.   
    string text = "The blue color value is " + pdfColor.Blue;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("Blue")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the blue color value.   
    Dim text As String = "The blue color value is " + pdfColor.Blue
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    C

    Gets or sets Cyan channel value.

    Declaration
    public float C { get; set; }
    Property Value
    Type Description
    System.Single

    The C.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("SlateBlue");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the cyan channel value. 
    string text = "The cyan channel value is " + pdfColor.C;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("SlateBlue")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the cyan channel value.   
    Dim text As String = "The cyan channel value is " + pdfColor.C
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Empty

    Gets a null color.

    Declaration
    public static PdfColor Empty { get; }
    Property Value
    Type Description
    PdfColor

    The empty.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Gets an empty PDF color instance.
    PdfColor color = PdfColor.Empty;
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Gets an empty PDF color instance.
    Dim color As PdfColor = PdfColor.Empty
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    G

    Gets or sets Green channel value.

    Declaration
    public byte G { get; set; }
    Property Value
    Type Description
    System.Byte

    The G.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("LawnGreen");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the green channel value.   
    string text = "The green channel value is " + pdfColor.G;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("LawnGreen")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the green channel value.   
    Dim text As String = "The green channel value is " + pdfColor.G
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Gray

    Gets or sets Gray channel value.

    Declaration
    public float Gray { get; set; }
    Property Value
    Type Description
    System.Single

    The gray.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("DarkSlateGray");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the gray channel value.   
    string text = "The gray channel value is " + pdfColor.Gray;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("DarkSlateGray")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the gray channel value.   
    Dim text As String = "The gray channel value is " + pdfColor.Gray
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Green

    Gets the green value

    Declaration
    public float Green { get; }
    Property Value
    Type Description
    System.Single

    The green.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("Green");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the green color value.   
    string text = "The green color value is " + pdfColor.Green;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("Green")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the green color value.   
    Dim text As String = "The green color value is " + pdfColor.Green
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    IsEmpty

    Gets whether the PDFColor is Empty or not.

    Declaration
    public bool IsEmpty { get; }
    Property Value
    Type Description
    System.Boolean

    true if this instance is empty; otherwise, false.

    Examples
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(Color.Empty);
    //Check the color.
    bool isEmpty = pdfColor.IsEmpty;
    Console.WriteLine("The Color is " + (isEmpty? "empty" : "not empty"));
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(Color.Empty)
    'Check the color.
    Dim isEmpty As Boolean = pdfColor.IsEmpty
    Console.WriteLine("The Color is " + (If(isEmpty, "empty", "not empty")))

    K

    Gets or sets Black channel value.

    Declaration
    public float K { get; set; }
    Property Value
    Type Description
    System.Single

    The K.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("DarkSlateGray");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the black channel value.   
    string text = "The black channel value is " + pdfColor.K;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("DarkSlateGray")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the black channel value.   
    Dim text As String = "The black channel value is " + pdfColor.K
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    M

    Gets or sets Magenta channel value.

    Declaration
    public float M { get; set; }
    Property Value
    Type Description
    System.Single

    The M.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("DarkSlateGray");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the megenta channel value.   
    string text = "The megenta channel value is " + pdfColor.M;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("DarkSlateGray")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the megenta channel value.   
    Dim text As String = "The megenta channel value is " + pdfColor.M
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    R

    Gets or sets Red channel value.

    Declaration
    public byte R { get; set; }
    Property Value
    Type Description
    System.Byte

    The R.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("Red");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the red channel value.   
    string text = "The red channel value is " + pdfColor.R;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("Red")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the red channel value.   
    Dim text As String = "The red channel value is " + pdfColor.R
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Red

    Gets the red color

    Declaration
    public float Red { get; }
    Property Value
    Type
    System.Single
    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("Red");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the red color value.   
    string text = "The red color value is " + pdfColor.Red;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("Red")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the red color value.   
    Dim text As String = "The red color value is " + pdfColor.Red
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Y

    Gets or sets Yellow channel value.

    Declaration
    public float Y { get; set; }
    Property Value
    Type Description
    System.Single

    The Y.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create color
    Color color = Color.FromName("YellowGreen");
    //Create a new PDF color instance.
    PdfColor pdfColor = new PdfColor(color);
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(pdfColor);
    //Get the yellow channel value.   
    string text = "The yellow channel value is " + pdfColor.Y;
    //Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create color
    Dim color As Color = Color.FromName("YellowGreen")
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(color)
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(pdfColor)
    'Get the yellow channel value.   
    Dim text As String = "The yellow channel value is " + pdfColor.Y
    'Draw string to PDF page.
    graphics.DrawString(text, font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Methods

    Equals(PdfColor)

    Determines if the specified color is equal to this one.

    Declaration
    public bool Equals(PdfColor colour)
    Parameters
    Type Name Description
    PdfColor colour

    The color.

    Returns
    Type Description
    System.Boolean

    True if the color is equal; otherwise - False.

    Examples
    //Create new PDF color.
    PdfColor color1 = new PdfColor(Color.Red);
    PdfColor color2 = new PdfColor(253, 0, 0);
    //Check both the color are equal.
    if(color1.Equals(color2))
    Console.WriteLine("Both the colors are same.");  
    'Create new PDF color.
    Dim color1 As New PdfColor(Color.Red)
    Dim color2 As New PdfColor(253, 0, 0)
    'Check both the color are equal.
    If color1.Equals(color2) Then
    Console.WriteLine("Both the colors are same.")
    End If

    Equals(Object)

    Determines whether the specified System.Object is equal to the current System.Object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj

    The System.Object to compare with the current System.Object.

    Returns
    Type Description
    System.Boolean

    True if the specified System.Object is equal to the current System.Object; otherwise - False.

    Examples
    //Create new PDF color.
    PdfColor color1 = new PdfColor(Color.Red);
    PdfColor color2 = new PdfColor(253, 0, 0);
    //Check both the color are equal.
    if(color1.Equals(color2))
    Console.WriteLine("Both the colors are same.");  
    'Create new PDF color.
    Dim color1 As New PdfColor(Color.Red)
    Dim color2 As New PdfColor(253, 0, 0)
    'Check both the color are equal.
    If color1.Equals(color2) Then
    Console.WriteLine("Both the colors are same.")
    End If

    GetHashCode()

    Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

    A hash code for the current System.Object.

    ToArgb()

    Creates the Alpha ,Red ,Green, and Blue value of this PDFColor structure.

    Declaration
    public int ToArgb()
    Returns
    Type Description
    System.Int32

    ARGB value.

    Examples
    //Create new PDF color.
    PdfColor color1 = new PdfColor(Color.LightBlue);
    //Get the ARGB value.
    int argb = color1.ToArgb();
    Console.WriteLine("ARGB: "+ argb); 
    'Create new PDF color.
    Dim color1 As New PdfColor(Color.LightBlue)
    'Get the ARGB value.
    Dim argb As Integer = color1.ToArgb()
    Console.WriteLine("ARGB: " + argb)

    Operators

    Equality(PdfColor, PdfColor)

    Operator ==.

    Declaration
    public static bool operator ==(PdfColor colour1, PdfColor colour2)
    Parameters
    Type Name Description
    PdfColor colour1

    The color 1.

    PdfColor colour2

    The color 2.

    Returns
    Type Description
    System.Boolean

    True if color 1 is equal to color 2; otherwise False.

    Examples
    //Create new PDF color.
    PdfColor color1 = new PdfColor(Color.Red);
    PdfColor color2 = new PdfColor(255, 0, 0);
    //Check both the color are equal.
    if (color1 == color2)
    Console.WriteLine("Both the colors are same.");        
    'Create new PDF color.
    Dim color1 As New PdfColor(Color.Red)
    Dim color2 As New PdfColor(255, 0, 0)
    'Check both the color are equal.
    If color1 = color2 Then
    Console.WriteLine("Both the colors are same.")      
    End If

    Implicit(PdfColor to Color)

    Implicit operator.

    Declaration
    public static implicit operator Color(PdfColor color)
    Parameters
    Type Name Description
    PdfColor color

    System.Drawing.Color.

    Returns
    Type Description
    System.Drawing.Color

    PDFColor.

    Examples
                 //Create a new PDF color instance.
                 PdfColor pdfColor = new PdfColor(200, 120, 80);
                 //Convert PDF color to System color.
                 System.Drawing.Color systemColor = pdfColor;
                 Console.WriteLine("Red: " + systemColor.R + " Green: " + systemColor.G + " Blue: " + systemColor.B);
    'Create a new PDF color instance.
    Dim pdfColor As New PdfColor(200, 120, 80)
    'Convert PDF color to System color.
    Dim systemColor As System.Drawing.Color = pdfColor
    Console.WriteLine("Red: " + systemColor.R + " Green: " + systemColor.G + " Blue: " + systemColor.B)

    Implicit(Color to PdfColor)

    Implicit operator.

    Declaration
    public static implicit operator PdfColor(Color color)
    Parameters
    Type Name Description
    System.Drawing.Color color

    System.Drawing.Color.

    Returns
    Type Description
    PdfColor

    PDFColor.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create PDF font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
    //Create PDF color.
    PdfColor color = System.Drawing.Color.Red;
    //Create new PDF brush.
    PdfBrush brush = new PdfSolidBrush(color);
    //Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create PDF font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular)
    'Create PDF color.
    Dim color As PdfColor = System.Drawing.Color.Red
    'Create new PDF brush.
    Dim brush As PdfBrush = New PdfSolidBrush(color)
    'Draw string to PDF page.
    graphics.DrawString("Hello World!", font, brush, PointF.Empty)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Inequality(PdfColor, PdfColor)

    Operator !=.

    Declaration
    public static bool operator !=(PdfColor colour1, PdfColor colour2)
    Parameters
    Type Name Description
    PdfColor colour1

    The color 1.

    PdfColor colour2

    The color 2.

    Returns
    Type Description
    System.Boolean

    True if color 1 is not equal to color 2; otherwise False.

    Examples
    //Create new PDF color.
    PdfColor color1 = new PdfColor(Color.Red);
    PdfColor color2 = new PdfColor(250, 0, 0);
    //Check both the color are equal.
    if (color1 != color2)
    Console.WriteLine("The colors are not same.");        
    'Create new PDF color.
    Dim color1 As New PdfColor(Color.Red)
    Dim color2 As New PdfColor(250, 0, 0)
    'Check both the color are equal.
    If color1 = color2 Then
    Console.WriteLine("The colors are not same.")      
    End If
    Back to top Generated by DocFX
    OSZAR »
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved
    OSZAR »