---
title: "Create a PDF/X-4 file with CMYK output intent"
canonical: https://www.graphicsmill.com/samples/Codecs/Pdf/CreateX4_cs
product: "Graphics Mill"
source: "Codecs/Pdf/CreateX4.cs"
---

# Create a PDF/X-4 file with CMYK output intent

This sample shows how to create a PDF/X-4 document with a CMYK output intent using GraphicsMill.
It demonstrates how to load a CMYK print profile, configure an ` OutputIntent `, initialize a
` PdfWriter ` with that intent, convert an RGB image to CMYK using color management, and draw it
onto a PDF page together with a solid CMYK-filled shape.

## Instruction

Use the PDF API to create a PDF/X-4 file that targets a specific CMYK print profile:
load the output ICC profile, configure the PDF output intent, create a CMYK page background,
color-manage an input RGB image into CMYK, and draw both the image and a CMYK rectangle onto the page.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
using (var profile = new ColorProfile("ISOcoated_v2_eci.icc"))
{
    // Create the output intent
    var intent = new OutputIntent()
    {
        Profile = profile,
        OutputConditionId = "ISOcoated_v2_eci",
        Info = "ISO Coated v2 (ECI) CMYK output profile for sheetfed offset printing on coated paper",
        OutputCondition = "Offset printing on coated paper (ISO 12647-2:2004 / Amd 1)",
        Registry = "http://www.eci.org",
    };

    // Create the PDF writer with the output intent
    using (var writer = new PdfWriter("x4_out.pdf", intent))
    using (var gr = writer.GetGraphics())
    using (var bitmap = new Bitmap("Apple.jpg"))
    {
        // Add a new page with a red background
        writer.AddPage(500, 500, RgbColor.Red.Convert(PixelFormat.Format32bppCmyk));

        gr.FillRectangle(new SolidBrush(new CmykColor(0, 0, 0, 255, 100)), 350, 350, 100, 100);

        // Prepare the image
        bitmap.Transforms.Resize(400, 400, ResizeInterpolationMode.Anisotropic9, ResizeMode.Fit);

        bitmap.ColorManagement.DestinationProfile = profile;
        bitmap.ColorManagement.Convert(PixelFormat.Format32bppCmyk);

        // Remove the color profile from the image
        bitmap.ColorProfile = null;

        // Draw the image
        gr.DrawImage(bitmap, 0, 0);

        writer.Close();
    }
}
```

## Explanation

The code:

- Loads the CMYK print profile from the file "ISOcoated_v2_eci.icc" into a ` ColorProfile `.
- Creates an ` OutputIntent ` object and assigns the profile and metadata such as
` OutputConditionId `, ` Info `, ` OutputCondition `, and ` Registry `.
- Initializes a ` PdfWriter ` with the output intent to produce a PDF/X-4-compatible file "x4_out.pdf".
- Gets a drawing ` Graphics ` object from the writer and loads the source image "Apple.jpg"
into a ` Bitmap `.
- Adds a 500x500 page and sets its background to red converted to CMYK using ` RgbColor.Red.Convert `.
- Draws a 100x100 CMYK rectangle in the bottom-right area of the page using ` FillRectangle `
and a ` CmykColor ` brush.
- Resizes the bitmap to fit within 400x400 pixels while preserving aspect ratio using the
` Resize ` transform in ` ResizeMode.Fit ` with ` ResizeInterpolationMode.Anisotropic9 `.
- Sets the bitmap’s ` DestinationProfile ` to the same CMYK profile and converts it to
` PixelFormat.Format32bppCmyk ` with color management.
- Clears the embedded color profile from the bitmap (` bitmap.ColorProfile = null `) so the
page relies on the output intent profile.
- Draws the CMYK bitmap onto the page at position (0, 0) using ` Graphics.DrawImage `.
- Closes the writer, finalizing the PDF/X-4 document as "x4_out.pdf" and produces a CMYK-ready file
suitable for coated-offset printing workflows.

## Tags

- [Color Management](<https://www.graphicsmill.com/samples/tags/color-management_md>): Color management with ICC profiles
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [PDF](<https://www.graphicsmill.com/samples/tags/pdf_md>): Importing and exporting PDF documents
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [ISOcoated\_v2\_eci.icc](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/ISOcoated_v2_eci_icc>) (download)
- [Apple.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Apple_jpg>) (preview)

## Output

- [x4\_out.png](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/x4_out_png>) (preview)
- [x4\_out.pdf](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/x4_out_pdf>) (download)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.ColorManagement](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorManagement.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.ColorProfile](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorProfile.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.Transforms](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md>)
- [Aurigma.GraphicsMill.CmykColor](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_CmykColor.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageWriter.Close](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_ImageWriter_Close.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_OutputIntent.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent.Info](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_OutputIntent_Info.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent.OutputCondition](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_OutputIntent_OutputCondition.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent.OutputConditionId](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_OutputIntent_OutputConditionId.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent.Profile](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_OutputIntent_Profile.htm.md>)
- [Aurigma.GraphicsMill.Codecs.OutputIntent.Registry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_OutputIntent_Registry.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,Color)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_AddPage_3_edd08af9.htm.md>)
- [Aurigma.GraphicsMill.Codecs.PdfWriter.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_PdfWriter_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Color.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Color_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorManagementProvider_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.DestinationProfile](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_ColorManagementProvider_DestinationProfile.htm.md>)
- [Aurigma.GraphicsMill.ColorProfile](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorProfile.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.FillRectangle(Brush,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillRectangle_5_2d30ad96.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeInterpolationMode.htm.md>)
- [Aurigma.GraphicsMill.Transforms.ResizeMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeMode.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.Resize(Int32,Int32,ResizeInterpolationMode,ResizeMode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_Resize_4_9f3f3567.htm.md>)
