API referenceGraphics

pdfCreateDeviceNColorSpace

Register a new DeviceN color space with one or more named

C
int32_t __stdcall pdfCreateDeviceNColorSpace(PPDF IPDF, PPAnsiChar Colorants, uint32_t NumColorants, const char* PostScriptFunc, TExtColorSpace Alternate, int32_t Handle);
Delphi
function pdfCreateDeviceNColorSpace(const IPDF: PPDF; Colorants: PPAnsiChar; NumColorants: Cardinal; const PostScriptFunc: PAnsiChar; Alternate: TExtColorSpace; Handle: Integer): Integer; stdcall;

Purpose. Register a new DeviceN color space with one or more named colorants and a PostScript tint-transform function.

Description. Requires a non-null Colorants array, NumColorants > 0, and a non-null PostScriptFunc; fails (-1) if any of those is missing. Reads NumColorants PAnsiChar entries from Colorants into an internal name array (a null entry becomes an empty string, not a failure). Maps Alternate the same coarse way as pdfChangeSeparationColor (previous chapter): 1→DeviceCMYK, 2→DeviceGray, anything else→DeviceRGB. The Handle parameter is accepted by the ABI but never read by the implementationCreateDeviceNColorSpace always allocates a fresh handle via RegisterColorSpace; there is no way to force a caller-chosen handle number through this call despite the parameter's presence.

Parameters.

ParameterDescription
IPDFDocument handle.
ColorantsArray of NumColorants colorant name strings.
NumColorantsNumber of colorants (must be > 0).
PostScriptFuncPostScript tint-transform function source (required, stored verbatim).
AlternateDevice alternate space — only CMYK(1)/Gray(2) distinguished, else RGB.
HandleAccepted but ignored — a new handle is always auto-allocated.

Return value. The new (auto-allocated) color-space handle on success; -1 if Colorants/NumColorants/PostScriptFunc requirements aren't met.

Remarks. Use pdfAddDeviceNSeparationsAttr/pdfAddDeviceNProcessAttr afterward to attach the /Separations/process-color attributes structure DeviceN spaces typically carry (not covered in this chapter — see the DeviceN attributes cluster).

See also. pdfChangeSeparationColor, pdfRenameSpotColor.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfCreateDeviceNColorSpace(IntPtr IPDF, IntPtr Colorants, uint NumColorants, [MarshalAs(UnmanagedType.LPStr)] string PostScriptFunc, TExtColorSpace Alternate, int Handle);
Area
Graphics
Category

Object Creation

Exported names

pdfCreateDeviceNColorSpace

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.