Skip to main content
Skip table of contents

Color creation and conversion

📌 Overview

This Mako example shows how to create colors in different ways, including creating a spot color. It produces a PDF with colored blocks of the colors made. See also "All" & "None" colorants in Mako for specific guidance on using “All” and “None” colorants.

⌨️ Sample Code

This sample produces a PDF with colored blocks of the colors made using the different methods. Full implementation available at Visual Studio Projects/CreateColorsAndShapes, Java Projects/CreateColorsAndShapes or Python Projects/CreateColorsAndShapes

Create colors

CPP
const auto mako = IJawsMako::create();
mako->enableAllFeatures(mako);

// Create a process color brush
const auto cyan = IDOMSolidColorBrush::createSolidCmyk(mako, 1.0, 0.0, 0.0, 0.0);

// Create some spot color brushes with types LAB, ICCBased and DeviceN

// Create an LAB colorspace with D65 white point and -128 to 127 ranges for a and b values
const auto labColorSpace = IDOMColorSpaceLAB::create(mako, 0.9504f, 1.0f, 1.0888f, 0.0, 0.0, 0.0, -128, 127, -128, 127);

// Create a device CMYK colorspace from an ICC profile
const auto iccBasedColorSpace = IDOMColorSpaceICCBased::create(
     mako, IDOMICCProfile::create(
        mako, IInputStream::createFromFile(
            mako, R"(C:\Windows\System32\spool\drivers\color\WebCoatedFOGRA28.icc)")));

// Create an LAB color
const auto pantoneBlue072C_lab = IDOMColor::create(mako, labColorSpace, 1.0, 17.64, 43.0, -76.0);

// Make a copy and convert to ICC space
auto pantoneBlue072C_fogra = clone(pantoneBlue072C_lab, mako);
pantoneBlue072C_fogra->setColorSpace(iccBasedColorSpace, eRelativeColorimetric, eBPCDefault, mako);

// Create a DeviceN color
const auto pantoneBlue072C_spot = MakeDeviceNColor(mako, "PANTONE BLUE 072 C", CDoubleVect{ 17.64, 43.0, -76.0 }, labColorSpace);

// Create spot color brushes
const auto labBrush = IDOMSolidColorBrush::create(mako, pantoneBlue072C_lab);
const auto iccBrush = IDOMSolidColorBrush::create(mako, pantoneBlue072C_fogra);
const auto deviceNBrush = IDOMSolidColorBrush::create(mako, pantoneBlue072C_spot);
C#
using var mako = IJawsMako.create();
IJawsMako.enableAllFeatures(mako);

// Create a process color brush
var cyan = IDOMSolidColorBrush.createSolidCmyk(mako, 1.0f, 0.0f, 0.0f, 0.0f);

// Create some spot color brushes with types LAB, ICCBased and DeviceN

// Create an LAB colorspace with D65 white point and -128 to 127 ranges for a and b values
var labColorSpace = IDOMColorSpaceLAB.create(mako, 0.9504f, 1.0f, 1.0888f, 0.0f, 0.0f, 0.0f, -128, 127, -128, 127);

// Create a device CMYK colorspace from an ICC profile
var iccBasedColorSpace = IDOMColorSpaceICCBased.create(
    mako, IDOMICCProfile.create(
        mako, IInputStream.createFromFile(
            mako, @"C:\Windows\System32\spool\drivers\color\WebCoatedFOGRA28.icc")));

// Create a LAB color
var pantoneBlue072C_lab = IDOMColor.create(mako, labColorSpace, 1.0, 17.64, 43.0, -76.0);

// Make a copy and convert to ICC space
IDOMColor pantoneBlue072C_fogra = IDOMColor.fromRCObject(pantoneBlue072C_lab.clone(mako));
pantoneBlue072C_fogra.setColorSpace(iccBasedColorSpace, eRenderingIntent.eRelativeColorimetric, eBlackPointCompensation.eBPCDefault, mako);

// Create a DeviceN color
var pantoneBlue072C_spot = MakeDeviceNColor(mako, "PANTONE BLUE 072 C", new CEDLVectDouble(new double[] { 17.64, 43.0, -76.0 }), labColorSpace);

// Create spot color brushes
var labBrush = IDOMSolidColorBrush.create(mako, pantoneBlue072C_lab);
var iccBrush = IDOMSolidColorBrush.create(mako, pantoneBlue072C_fogra);
var deviceNBrush = IDOMSolidColorBrush.create(mako, pantoneBlue072C_spot);
JAVA
var mako = IJawsMako.create();
IJawsMako.enableAllFeatures(mako);
var factory = mako.getFactory();

// Create a process color brush
var cyan = IDOMSolidColorBrush.createSolidCmyk(factory, 1.0f, 0.0f, 0.0f, 0.0f);

// Create some spot color brushes with types LAB, ICCBased and DeviceN

// Create an LAB colorspace with D65 white point and -128 to 127 ranges for a and b values
var labColorSpace = IDOMColorSpaceLAB.create(factory, 0.9504f, 1.0f, 1.0888f, 0.0f, 0.0f, 0.0f, -128, 127, -128, 127);

// Create a device CMYK colorspace from an ICC profile
var iccBasedColorSpace = IDOMColorSpaceICCBased.create(
    factory, IDOMICCProfile.create(
        factory, IInputStream.createFromFile(
            factory, "C:\\Windows\\System32\\spool\\drivers\\color\\WebCoatedFOGRA28.icc")));

// Create a LAB color
var pantoneBlue072C_lab = IDOMColor.create(factory, labColorSpace, 1.0, 17.64, 43.0, -76.0);

// Make a copy and convert to ICC space
IDOMColor pantoneBlue072C_fogra = IDOMColor.fromRCObject(pantoneBlue072C_lab.clone(factory));
pantoneBlue072C_fogra.setColorSpace(iccBasedColorSpace, eRenderingIntent.eRelativeColorimetric, eBlackPointCompensation.eBPCDefault, factory);

// Create a DeviceN color
var pantoneBlue072C_spot = MakeDeviceNColor(factory, "PANTONE BLUE 072 C", new CEDLVectDouble(new double[] { 17.64, 43.0, -76.0 }), labColorSpace);

// Create spot color brushes
var labBrush = IDOMSolidColorBrush.create(factory, pantoneBlue072C_lab);
var iccBrush = IDOMSolidColorBrush.create(factory, pantoneBlue072C_fogra);
var deviceNBrush = IDOMSolidColorBrush.create(factory, pantoneBlue072C_spot);

Use colors to make blocks

CPP
// Draw some boxes
const auto masterBoxSize = FPoint(90, 90);
auto boxSize = masterBoxSize;
auto origin = FPoint(85, 85);
auto start = origin;

// Draw Cyan box
auto box = FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage->appendChild(IDOMPathNode::createFilled(mako, IDOMPathGeometry::create(mako, box), cyan));
start.x += boxSize.x;

// Draw LAB box 
box = FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage->appendChild(IDOMPathNode::createFilled(mako, IDOMPathGeometry::create(mako, box), labBrush));
start.x += boxSize.x;

// Draw ICC box
box = FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage->appendChild(IDOMPathNode::createFilled(mako, IDOMPathGeometry::create(mako, box), iccBrush));
start.x += boxSize.x;

// Draw DeviceN box
box = FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage->appendChild(IDOMPathNode::createFilled(mako, IDOMPathGeometry::create(mako, box), deviceNBrush));
start.x += boxSize.x;
C#
// Set some boxes
var masterBoxSize = new FPoint(90, 90);
var boxSize = new FPoint(masterBoxSize);
var origin = new FPoint(85, 85);
var start = new FPoint(origin);

// Draw Cyan box
var box = new FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage.appendChild(IDOMPathNode.createFilled(mako, IDOMPathGeometry.create(mako, box), cyan));
start.x += boxSize.x;

// Draw LAB box
box = new FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage.appendChild(IDOMPathNode.createFilled(mako, IDOMPathGeometry.create(mako, box), labBrush));
start.x += boxSize.x;

// Draw ICC box
box = new FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage.appendChild(IDOMPathNode.createFilled(mako, IDOMPathGeometry.create(mako, box), iccBrush));
start.x += boxSize.x;

// Draw DeviceN box
box = new FRect(start.x, start.y, boxSize.x, boxSize.y);
fixedPage.appendChild(IDOMPathNode.createFilled(mako, IDOMPathGeometry.create(mako, box), deviceNBrush));
start.x += boxSize.x;
JAVA
// Draw some boxes
FPoint masterBoxSize = new FPoint(90, 90);
var boxSize = new FPoint(masterBoxSize);
var origin = new FPoint(85, 85);
var start = new FPoint(origin);

// Draw Cyan box
var box = new FRect(start.getX(), start.getY(), boxSize.getX(), boxSize.getY());
fixedPage.appendChild(IDOMPathNode.createFilled(factory, IDOMPathGeometry.create(factory, box), cyan));
start.setX(start.getX() + boxSize.getX());

// Draw LAB box
box = new FRect(start.getX(), start.getY(), boxSize.getX(), boxSize.getY());
fixedPage.appendChild(IDOMPathNode.createFilled(factory, IDOMPathGeometry.create(factory, box), labBrush));
start.setX(start.getX() + boxSize.getX());

// Draw ICC box
box = new FRect(start.getX(), start.getY(), boxSize.getX(), boxSize.getY());
fixedPage.appendChild(IDOMPathNode.createFilled(factory, IDOMPathGeometry.create(factory, box), iccBrush));
start.setX(start.getX() + boxSize.getX());

// Draw DeviceN box
box = new FRect(start.getX(), start.getY(), boxSize.getX(), boxSize.getY());
fixedPage.appendChild(IDOMPathNode.createFilled(factory, IDOMPathGeometry.create(factory, box), deviceNBrush));
start.setX(start.getX() + boxSize.getX());

☑️ Conclusion

The Mako SDK provides versatile methods for color creation and conversion, allowing users to work with various color spaces and profiles. By following the provided sample code, users can create colors in different ways, including spot colors, and convert them across color spaces. This capability is essential for producing accurate and consistent color outputs in PDFs.

📚 Additional Resources

If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.