向pdf 0 scn添加专色(pdcolor)(pdseparation)

s3fp2yjn  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(279)

我面临的问题是,我试图绘制一个矩形与专色(pdseparation)一个笔划和一个非笔划(填充)。
第一个颜色值:spotcolorname=stroke color 6,r=255,g=153,b=51
第二个颜色值:spotcolorname=fill color 6,r=0,g=0,b=255
这是pdf输出的屏幕截图

下面是创建分隔和颜色的代码

private PDColor createSpotColorFromRGB(String spotColorName, int r, 
    int g, int b) throws IOException {
    PDSeparation seperation = new PDSeparation();
    COSDictionary dictionary = new COSDictionary();
    COSArray C0 = new COSArray();
    COSArray C1 = new COSArray();
    COSArray range = new COSArray();
    COSArray domain = new COSArray();
    float[] components = null;

    seperation.setColorantName(spotColorName);

    components = new float[] { r / 255f, g / 255f, b / 255f };

    seperation.setAlternateColorSpace(PDDeviceRGB.INSTANCE);

    C0.add(COSInteger.ZERO);
    C0.add(COSInteger.ZERO);
    C0.add(COSInteger.ZERO);

    range.add(COSInteger.ZERO);
    range.add(COSInteger.ONE);
    range.add(COSInteger.ZERO);
    range.add(COSInteger.ONE);
    range.add(COSInteger.ZERO);
    range.add(COSInteger.ONE);

    C1.add(COSInteger.ONE);
    C1.add(COSInteger.ONE);
    C1.add(COSInteger.ONE);

    domain.add(COSInteger.ZERO);
    domain.add(COSInteger.ONE);

    dictionary.setItem(COSName.C0, C0);
    dictionary.setItem(COSName.C1, C1);
    dictionary.setItem(COSName.DOMAIN, domain);
    dictionary.setItem(COSName.FUNCTION_TYPE, COSInteger.TWO);
    dictionary.setItem(COSName.N, COSInteger.ONE);
    dictionary.setItem(COSName.RANGE, range);

    PDFunction functionTyp2 = new PDFunctionType2(dictionary);

    seperation.setTintTransform(functionTyp2);

    return new PDColor(components, seperation);
}

然后我将生成的颜色设置为页面内容流

outputPageContentStream.setNonStrokingColor(fillColor);

outputPageContentStream.setStrokingColor(strokeColor);

只显示两种颜色中的一种颜色,显示带有1 scn/scn的颜色。
附加输出pdffile:httpshttp://docdro.id/0svsuwe
绘图代码为:

outputPageContentStream.saveGraphicsState();
outputPageContentStream.setNonStrokingColor(fillingColorForDrawingPDColor);
outputPageContentStream.setStrokingColor(strokingColorForDrawingPDColor);
outputPageContentStream.moveTo(a, b);
outputPageContentStream.lineTo(a + c, b);
outputPageContentStream.lineTo(a + c, b - d);
outputPageContentStream.lineTo(a, b - d);
outputPageContentStream.closePath();
outputPageContentStream.fillAndStroke();
outputPageContentStream.restoreGraphicsState();

有人能帮忙吗?

nc1teljy

nc1teljy1#

我用pdfbox pdfdebugger查看了这个文件,cs1为0(屏幕截图中的“0scn”)意味着它将显示为白色(您应该看看“fillingcolorfordrawingpcolor”的创建。

这是因为c0(下限,值0)是(1,1,1),它是白色的。c1(上限,值1)是蓝色的(0,0,1)。颜色之间的颜色由色调变换函数计算。
更新:
此代码

components = new float[] { r / 255f, g / 255f, b / 255f };
...
return new PDColor(components, seperation);

表示误解。分离颜色只需要一种颜色,即介于0和1之间的颜色。最终的颜色是“彩色的”,这是因为c0(最小值)和c1(最大值)中的值以及在这两个值之间创建颜色的函数。
rgb是可选颜色空间的“目标”颜色空间。分离颜色用于“特殊”颜色,例如金色、闪光、金属色、荧光色等。替代颜色空间模拟实际颜色不可用的情况(例如显示)。
在源代码(或此处)中的pdseparation示例中

PDColor color = new PDColor(new float[]{0.5f}, spotColorSpace);

相关问题