---
title: "Create a die-cut outline around artwork"
canonical: https://www.graphicsmill.com/samples/Drawing/Paths/CreateDieCutOutline_cs
product: "Graphics Mill"
source: "Drawing/Paths/CreateDieCutOutline.cs"
---

# Create a die-cut outline around artwork

This sample shows how to build the cut line of a sticker from the transparency of its artwork and write it to a print-ready PDF. ` Path.GetContour ` traces the outline of the opaque part of the image with sub-pixel accuracy, ` Path.Inflate ` grows it by the bleed and closes the narrow gaps between separate parts, ` Path.GetOuterContours ` drops the holes the cutter should not follow, and ` Path.FitCurves ` turns the traced polyline into smooth Bezier curves. The outline is stroked with a "CutContour" spot colour, the name cutting plotters and RIPs look for.

## Instruction

Use the drawing API to create a die-cut sticker from a PNG with transparency: trace the alpha channel into a vector path, grow it by a bleed, merge nearby parts into one outer outline, fit smooth curves, and write the artwork together with the outline stroked in a CutContour spot colour to a PDF page.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var artwork = new Bitmap("Stamp.png"))
{
    float bleed = UnitConverter.ConvertUnitsToPixels(artwork.DpiX, 0.125f, Unit.Inch);
    float closing = UnitConverter.ConvertUnitsToPixels(artwork.DpiX, 0.25f, Unit.Inch);

    // The boundary of the area where the artwork is at least half opaque.
    var outline = Path.GetContour(artwork, Channel.Alpha, 0.5f);

    // Growing by more than needed and shrinking back joins the parts that are closer
    // than 2 * closing (the postmark lines and the stamp) into one shape.
    outline.Inflate(bleed + closing, LineJoin.Round);
    outline.Inflate(-closing, LineJoin.Round);

    // The cutter follows the outer edge only, as smooth curves.
    outline = outline.GetOuterContours();
    outline.FitCurves(0.5f);

    using (var writer = new PdfWriter("CreateDieCutOutline.pdf"))
    using (var graphics = writer.GetGraphics())
    {
        writer.AddPage(artwork.Width + (2 * bleed), artwork.Height + (2 * bleed), artwork.DpiX, artwork.DpiY);

        graphics.DrawImage(artwork, bleed, bleed);

        outline.Translate(bleed, bleed);

        var cutContour = new SpotColor(new Ink("CutContour", new RgbColor(236, 0, 140)), 255);

        graphics.DrawPath(new Pen(cutContour, 1f), outline);
    }
}
```

## Explanation

The code:

- Loads the artwork "Stamp.png" with its alpha channel into a ` Bitmap ` and converts the bleed and the gap size from inches to pixels with ` UnitConverter.ConvertUnitsToPixels `.
- Traces the boundary of the pixels that are at least half opaque with ` Path.GetContour ` on ` Channel.Alpha `.
- Grows the outline with ` Path.Inflate ` by the bleed plus a closing distance and shrinks it back by the closing distance, so parts closer than twice that distance merge into one shape; round joins keep the corners smooth.
- Keeps only the outer boundary with ` Path.GetOuterContours ` and replaces the polyline with Bezier curves using ` Path.FitCurves `.
- Creates a ` PdfWriter ` page large enough for the artwork and the bleed, draws the artwork, and moves the outline to match it with ` Path.Translate `.
- Strokes the outline with a ` Pen ` in a ` SpotColor ` of the "CutContour" ` Ink ` and saves "CreateDieCutOutline.pdf".

## Tags

- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Path](<https://www.graphicsmill.com/samples/tags/path_md>): Building, offsetting and combining vector paths
- [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

- [Stamp.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/Stamp_png>) (preview)

## Output

- [CreateDieCutOutline.pdf](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/CreateDieCutOutline_pdf>) (download)
- [CreateDieCutOutline.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/CreateDieCutOutline_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Channel](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Channel.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.Drawing.Graphics.DrawImage(Bitmap,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawImage_3_b9413d4f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawPath(Pen,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawPath_2_77634c23.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LineJoin](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_LineJoin.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.FitCurves(Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_FitCurves_1_7a94462e.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.GetContour(Bitmap,Channel,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_GetContour_3_aed77fd4.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.GetOuterContours](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_GetOuterContours.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Inflate(Single,LineJoin)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Inflate_2_52356a13.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Translate(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Translate_2_427c5821.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.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>)
- [Aurigma.GraphicsMill.Unit](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Unit.htm.md>)
- [Aurigma.GraphicsMill.UnitConverter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_UnitConverter.htm.md>)
- [Aurigma.GraphicsMill.UnitConverter.ConvertUnitsToPixels(Single,Single,Unit)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_UnitConverter_ConvertUnitsToPixels_3_1df1b0a2.htm.md>)
