Q: Is there any way to create a PANTONE color (PANTONE 00001 A) ?
Right now I am forced to copy color resource from the designer PDF
file.
----------------
A: At the moment there is no simple way to create PANTONE and other
names colors.
Spot color can be represented in PDF using 'Separation' or 'DeviceN'
color spaces.
A separation color space can be treated similarly to grayscale color
space. For details on separation color space, please refer to section
4.5.5 'Special Color Spaces' in PDF Reference Manual
(http://www.pdftron.com/downloads/PDFReference16.pdf).
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 is similar.
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)
...