How do I create a Separation color space in PDF?

Q: I need to create Separation color space using PDFNet SDK. Normaly
the customer include a TIFF 1bpp into the PDF with ColorSpace /
Separation and CMYK tint value. For
example:

.. obj
/Separation
/Cyan
/DeviceCMYK
10 0 R

10 0 obj
<<
/FunctionType 0
/C0 [0 0 0 0]
/C1 [1 0 0 0]
/Range [0 1 0 1 0 1 0 1]
/Domain [0 1]
/N 1

It would be very helpful if you have any information or code on how to
create Separation color space using PDFTron toolkit. Thanks!
--------
A: The following C# pseudocode can be used to create a separation
color space based on a PostScript function:

static ColorSpace CreateSpotColorSpace(PDFDoc doc)
{
  Obj sep_cs = doc.CreateIndirectArray();

  sep_cs.PushBackName("Separation");
  sep_cs.PushBackName("LogoGreen"); // The name of the colorant
  sep_cs.PushBackName("DeviceCMYK"); // Alternate color space

  // Create tint function (using PostScript calculator function).
  // Tint function is used to transform a tint value into color
  // component values in the alternate color space.
  string ps_funct = "{ dup 0.84 mul exch 0.00 exch dup 0.44 mul exch
0.21 mul }";
  Obj tint_funct = doc.CreateIndirectStream(new
System.Text.UTF8Encoding().GetBytes(ps_funct));
  tint_funct.PutNumber("FunctionType", 4);

  Obj tint_domain = tint_funct.PutArray("Domain");
  tint_domain.PushBackNumber(0); // Gray
  tint_domain.PushBackNumber(1);

  Obj tint_range = tint_funct.PutArray("Range");
  tint_range.PushBackNumber(0); // C
  tint_range.PushBackNumber(1);
  tint_range.PushBackNumber(0); // M
  tint_range.PushBackNumber(1);
  tint_range.PushBackNumber(0); // Y
  tint_range.PushBackNumber(1);
  tint_range.PushBackNumber(0); // K
  tint_range.PushBackNumber(1);

  sep_cs.PushBack(tint_funct);
  return new ColorSpace(sep_cs);
}

The sample code in C++ or JAVA should be almost identical.

The resulting color space can be reused throughout the PDF document.
For example:

.. create ElementBuilder/ElementWriter (see ElementBuilder sample
project )
...
ColorSpace cs = CreateSpotColorSpace(doc);
...
Element rect = builder.CreateRect(0, 0, 100, 100);
rect.SetPathStroke(true);
rect.GetGState().SetStrokeColorSpace(cs);
rect.GetGState().SetStrokeColor(new ColorPt(1));
writer.WriteElement(rect)
...

Thanks for you help. I have the Red PostScript book and I read all
mensages in the KB to better understand how put the postscript
function. Thank very much for you help.

My final code is similar:

void CreateColorSpaceSeparate(ColorSpace& sep,unsigned color) {
Obj aSepCS = doc.CreateIndirectArray();
aSepCS.PushBackName("Separation");

char inkFunction[256];

switch(color)
{
case 1:
   aSepCS.PushBackName("Cyan");
   strcpy(inkFunction,"{ 0 exch 0 exch 0 exch }");
   break;
case 2:
   aSepCS.PushBackName("Magenta");
   strcpy(inkFunction,"{ 0 exch 0 exch 0 }");
   break;
case 3:
   aSepCS.PushBackName("Yellow");
   strcpy(inkFunction,"{ 0 exch 0 0 }");
   break;
case 4:
   aSepCS.PushBackName("Black");
   strcpy(inkFunction,"{ 0 0 0 }");
   break;
}
aSepCS.PushBackName("DeviceCMYK");
Obj sInkFunction =
doc.CreateIndirectStream(inkFunction,strlen(inkFunction));
sInkFunction.PutNumber("FunctionType",4);
Obj aDomain = sInkFunction.PutArray("Domain");
aDomain.PushBackNumber(0);
aDomain.PushBackNumber(1);
Obj aRange = sInkFunction.PutArray("Range");
for(int i = 0; i < 4; ++i ) {
   aRange.PushBackNumber(0);
   aRange.PushBackNumber(1);
}
aSepCS.PushBack(sInkFunction);
cs = ColorSpace(aSepCS);
}