Reputation: 3638
Following problem: I draw a magenta line on a pdf document. Before that I create a new color object like:
CMYKColor magentaColor = new CMYKColor(0.f, 1.f, 0.f, 0.f);
Then I set this color for the PDFContentByte like:
PdfContentByte cb = pdfWriter.getDirectContent();
cb.setColorStroke(magentaColor);
with pdfWriter being given the constructor as a parameter to create an instance of a class I use the PDFDirectContent in. Then I use PDFContentByte#moveTo() and PDFContentByte#lineTo() methods to draw my line. What I can not understand is why the line color on the pdf document is not 100% magenta but contains around 44% yellow. Here you can find the pdf with the described line(s).
Upvotes: 0
Views: 328
Reputation: 108
This seems to be a Colormanagement Issue. When drawing a 100% magenta line CMYK(0,100,0,0) and convert the document to RGB back and forth the line is no longer 100% magenta only.
The reason for this is, RGB (and CIELab) both are 3dimensional color spaces whereas CMYK has 4 dimensions. Only three dimensions are needed in order to describe the visual impression of a color.
Using the 4th dimensions in CMYK you are able to manage the configuration of your color. Whereas RGB and CIELab provide just ONE configuration for a specific color, CMYK provides an amount of configurations for describing one and the same visual impression.
For example, the color code for a 30% grey is RGB(74,74,75). Using CMYK you can describe one and the same point with CMYK(0,0,0,30) (black only) or CMYK(25,18,17,0) (without black). Both CMYK Configurations have one and the same visual impression. This behavior is used for UCR (Under Color Removal) and GCR (Grey Component Replacement).
So, please ensure that your PDF is not being converted unnecessarily to RGB (or any other color space) back and forth.
Upvotes: 2
Reputation: 77528
Please take a look at the DrawingLines example:
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfContentByte canvas = writer.getDirectContent();
CMYKColor magentaColor = new CMYKColor(0.f, 1.f, 0.f, 0.f);
canvas.setColorStroke(magentaColor);
canvas.moveTo(36, 36);
canvas.lineTo(36, 806);
canvas.lineTo(559, 36);
canvas.lineTo(559, 806);
canvas.closePathStroke();
document.close();
}
It results in the file draw_lines.pdf:
The color is magenta only:
When I look at your PDF, I see a different value:
Where I expect 0 1 0 0 K
, I see 0 1 0.44 0 K
. I also see that you are using something that is marked /ITXT: 4.2.0
. The prefix ITXT
was registered at ISO by iText Group NV. Only iText Group is allowed to use this prefix in its software. You are using software with version number 4.2.0. iText Group NV has never released iText 4.2.0. It is a rogue version.
Please share this with the people who forced you to use this unofficial version and tell them that they should upgrade.
Upvotes: 2