添加专色(PDColor)(PDSeparation)到PDF 0 SCN
Adding spot color (PDColor) (PDSeparation) to PDF 0 SCN
我遇到了一个问题,我正在尝试使用专色 (PDSeparation) 绘制一个矩形,一种用于描边,一种用于非描边(填充)。
第一个颜色值:spotColorName = 笔触颜色 6,R = 255,G = 153,B = 51
第二种颜色值:spotColorName = 填充颜色 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);
2种颜色中只显示一种颜色,显示1种scn/SCN的颜色。
附上输出PDF文件:https://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();
有人可以帮忙吗?
我用 PDFBox PDFDebugger 查看文件,cs1 为 0(屏幕截图中的“0 scn”)意味着它将显示为白色。 (你应该看看“fillingColorForDrawingPDColor”的创建)。
那是因为C0(下界,值为0)是(1, 1, 1),是白色的。 C1(上限,值 1)是 (0, 0, 1),它是蓝色的。之间的颜色由tint transform函数计算得到。
更新:
这个代码
components = new float[] { r / 255f, g / 255f, b / 255f };
...
return new PDColor(components, seperation);
说明有误会。分色只需要一种颜色,介于0和1之间。最终颜色是“彩色”是因为C0(最小值)和C1(最大值)中的值以及创建颜色之间的函数。
RGB 是替代色彩空间的“目标”色彩空间。分离色用于“特殊”颜色,例如金色、闪光、金属、荧光等。替代色彩空间模拟了实际颜色不可用的情况(例如显示)。
在源代码(或here)的PDSeparation示例中有这个
PDColor color = new PDColor(new float[]{0.5f}, spotColorSpace);
我遇到了一个问题,我正在尝试使用专色 (PDSeparation) 绘制一个矩形,一种用于描边,一种用于非描边(填充)。
第一个颜色值:spotColorName = 笔触颜色 6,R = 255,G = 153,B = 51
第二种颜色值:spotColorName = 填充颜色 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);
2种颜色中只显示一种颜色,显示1种scn/SCN的颜色。
附上输出PDF文件:https://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();
有人可以帮忙吗?
我用 PDFBox PDFDebugger 查看文件,cs1 为 0(屏幕截图中的“0 scn”)意味着它将显示为白色。 (你应该看看“fillingColorForDrawingPDColor”的创建)。
那是因为C0(下界,值为0)是(1, 1, 1),是白色的。 C1(上限,值 1)是 (0, 0, 1),它是蓝色的。之间的颜色由tint transform函数计算得到。
更新:
这个代码
components = new float[] { r / 255f, g / 255f, b / 255f };
...
return new PDColor(components, seperation);
说明有误会。分色只需要一种颜色,介于0和1之间。最终颜色是“彩色”是因为C0(最小值)和C1(最大值)中的值以及创建颜色之间的函数。
RGB 是替代色彩空间的“目标”色彩空间。分离色用于“特殊”颜色,例如金色、闪光、金属、荧光等。替代色彩空间模拟了实际颜色不可用的情况(例如显示)。
在源代码(或here)的PDSeparation示例中有这个
PDColor color = new PDColor(new float[]{0.5f}, spotColorSpace);