I need to add a new color separation with the name “White” and the value “#3cf”, But there is no direct official PDFNet.PDFDoc API to do it,is there any way to add it with PDFNet.PDFDoc API of javascript version?
I got this error message while executing the javascript version of the above answer:“Cannot read properties of undefined (reading ‘length’)”,and a warning before the error:"[WARNING], the object was not found in the deallocation list. Deallocating may cause errors.",they were threw out by doc.createIndirectStream function.Btw the JS version of “createIndirectStream” function requires a second argument which type is “PDFNet.Filter”,I don’t know how to config it, here is the code:
async function createSpotColorSpace(doc) {
let sep_cs = await doc.createIndirectArray();
sep_cs.pushBackName("Separation");
sep_cs.pushBackName("LogoGreen"); // The name of the colorant
sep_cs.pushBackName("DeviceCMYK"); // Alternate color space
let ps_funct = "{ dup 0.84 mul exch 0.00 exch dup 0.44 mul exch 0.21 mul }";
let encoded = new TextEncoder().encode(ps_funct);
let tint_funct = await doc.createIndirectStream(encoded, new PDFNet.Filter()); //[WARNING], the object was not found in the deallocation list. Deallocating may cause errors. Error:Cannot read properties of undefined (reading 'length')
tint_funct.putNumber("FunctionType", 4);
let tint_domain = await tint_funct.putArray("Domain");
window.aaa = tint_domain;
tint_domain.pushBackNumber(0); // Gray
tint_domain.pushBackNumber(1);
tint_funct.put("Domain", tint_domain)
let tint_range = await 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);
tint_funct.put("Range", tint_range);
sep_cs.pushBack(tint_funct);
return new PDFNet.ColorSpace(sep_cs);
}