---
title: "Replace Process Color"
canonical: https://www.graphicsmill.com/samples/Codecs/SpotColors/ReplaceProcessColor_cs
product: "Graphics Mill"
source: "Codecs/SpotColors/ReplaceProcessColor.cs"
---

# Replace Process Color

Converts the specified process color into a spot color saving graphics container to the PDF format.

## Instruction

Write a C# program that converts a specified process color into a spot color and saves the graphics container to a PDF format.

## Usings

```csharp
using System.Linq;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
public static class Extensions
{
    public static bool IsBlack(this Color color)
    {
        var grayColor = (GrayscaleColor)color.Convert(PixelFormat.Format8bppGrayscale);

        return grayColor.L < 20;
    }

    public static void ReplaceProcessColors(this GraphicsContainer container, SpotColor spotColor)
    {
        foreach (var item in container.Items.OfType<ShapeItem>())
        {
            if (item.Brush != null && item.Brush is SolidBrush && (item.Brush as SolidBrush).Color.IsBlack())
            {
                item.Brush = new SolidBrush(spotColor);
            }
        }

        foreach (var item in container.Items.OfType<ContainerItem>())
        {
            item.GraphicsContainer.ReplaceProcessColors(spotColor);
        }
    }
}

internal class ReplaceProcessColor
{
    public static void Run()
    {
        using (var reader = new PdfReader("Seal.pdf"))
        using (var gc = reader.Frames[0].GetContent())
        using (var writer = new PdfWriter("Process2SpotColor.pdf"))
        using (var gr = writer.GetGraphics())
        {
            writer.AddPage(gc.Width, gc.Height, gc.DpiX, gc.DpiY);

            var ink = new Ink("PANTONE Red 032 C", new RgbColor(243, 40, 55));
            var spotColor = new SpotColor(ink, 255);

            gc.ReplaceProcessColors(spotColor);

            gr.DrawContainer(gc, 0, 0);
        }
    }
}
```

## Explanation

Below is a C# code sample that demonstrates how to convert a process color into a spot color and save the graphics container to a PDF file.
The `ReplaceProcessColors` method is used to replace colors in a `GraphicsContainer` with a spot color. The code utilizes `PdfWriter`, `PdfReader`,
and a custom extension method to perform this task:

This code replaces process colors (e.g., black) with a specified PANTONE spot color in a PDF document and saves the resulting content to a new file.

## Tags

- [Modify Container](<https://www.graphicsmill.com/samples/tags/modify-container_md>): Editing items inside graphics containers
- [PDF](<https://www.graphicsmill.com/samples/tags/pdf_md>): Importing and exporting PDF documents
- [Spot Color](<https://www.graphicsmill.com/samples/tags/spot_md>): Using spot colors in images

## Input

- [Seal.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Seal_pdf>) (download)

## Output

- [Process2SpotColor.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Process2SpotColor_pdf>) (download)
- [Process2SpotColor.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Process2SpotColor_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.PdfFrame.GetContent](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfFrame_GetContent.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_PdfReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_PdfWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.AddPage(Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_AddPage_4_37f6c741.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Color](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Color.htm.md>)
- [Aurigma.GraphicsMill.Color.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Color_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ContainerItem](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ContainerItem.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ContainerItem.GraphicsContainer](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ContainerItem_GraphicsContainer.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawContainer(GraphicsContainer,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawContainer_3_098aa7ce.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_GraphicsContainer.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.GraphicsContainer.Items](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_GraphicsContainer_Items.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeItem](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_ShapeItem.htm.md>)
- [Aurigma.GraphicsMill.Drawing.ShapeItem.Brush](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_ShapeItem_Brush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush.Color](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_SolidBrush_Color.htm.md>)
- [Aurigma.GraphicsMill.GrayscaleColor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_GrayscaleColor.htm.md>)
- [Aurigma.GraphicsMill.GrayscaleColor.L](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_GrayscaleColor_L.htm.md>)
- [Aurigma.GraphicsMill.Ink](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Ink.htm.md>)
- [Aurigma.GraphicsMill.SpotColor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_SpotColor.htm.md>)
