Am 25.03.2015 um 22:52 schrieb Floris:
Hey there,

I am struggeling getting the PDDeviceN color space to work. I am trying to create a simple page with one rectangle having a color defined against a DeviceN space. I tried the following:

PDDeviceN cs =newPDDeviceN();
cs.setAlternateColorSpace(PDDeviceCMYK.INSTANCE);
cs.setColorantNames(Arrays.asList("Cyan","Magenta","Yellow","Black","Orange","Green"));

PDFunction func;
COSArray domains =newCOSArray();
COSArray ranges =newCOSArray();

domains.setFloatArray(new float[]{0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f}); ranges.setFloatArray(new float[]{0.0f,1.0f,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f});

COSDictionary dict=newCOSDictionary();
dict.setItem(COSName.FUNCTION_TYPE, COSInteger.get(4));
dict.setItem(COSName.DOMAIN, domains);
dict.setItem(COSName.RANGE, ranges);

try{
    func = PDFunction.create(tintdata);
        cs.setTintTransform(func);
}catch(IOException e) {
        e.printStackTrace();
}

This results in a NullPointerError in the first row of the try-part. The type4-function should just pop the first two values (to get from CMYKOG to CMYK). Could someone give me a jump start on how to define a PDDeviceN space?

Have a nice day,
Floris



Hello,

- tintdata is not defined
- the postscript code of the type4 function is missing

Here's an excerpt of a PDF file with a type 4 function:


48 0 obj
<<
/FunctionType 4
/Domain [0 1]
/Range [0 1 0 1 0 1 0 1]
/Length 62
>>
stream
{dup 0.37 mul exch dup 0 mul exch dup 0.34 mul exch 0.34 mul }
endstream
endobj

i.e. your function must have a stream which contains the postscript code. Thus call PDFunction.create() with a COStream. This object should have the dictionary that you already have, and as stream the "code" of the function.


COSDictionary dict=newCOSDictionary();
dict.setItem(COSName.FUNCTION_TYPE, COSInteger.get(4));
dict.setItem(COSName.DOMAIN, domains);
dict.setItem(COSName.RANGE, ranges);

String functionText = "{ push pop whatever }";

COSStream functionStream = new COSStream(dict, new RandomAccessBuffer());
OutputStream out = functionStream.createUnfilteredStream();
out.write(functionText.getBytes("US-ASCII"));
out.close();

func = PDFunction.create(functionStream);


I didn't test this code. If it doesn't work, please post some complete code that creates a PDF (that fails) and I'll try to help you more (However I can't help you with the postscript code).

Tilman

PS: always mention the version when you ask a question (in your case probably 1.8.*)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to