Search code examples
c#itextcmyk

ITextSharp, ITextExtractionStrategy Extract the Color (Pantone,CMYK)


I Would like to extract the extract Pantone Color from an PDF by using ITextSharp.

My code was taken from Chris Haas awnser. It was heavily modified to extract Words with position for it ( not just Chunks ) but still the same in its core. Now i have to extract more then the RGB values like the CMYK values or the Pantone Colors, stored inside the PDF.

public void RenderText(TextRenderInfo renderInfo)
{
     var colorSupported = renderInfo.GetFillColor();
     ...
}

or

renderInfo.GetStrokeColor();

does not fit my needs. I would like to extract More then RGB.


Solution

  • I assume you say

    renderInfo.GetFillColor() or renderInfo.GetStrokeColor() does not fit my needs. I would like to extract More then RGB.

    because those methode return a BaseColor which indeed only offers RGB values.

    If you inspect the type hierarchy more exactly, though, you will notice that there are multiple classes derived from BaseColor, namely CMYKColor, DeviceNColor, GrayColor, LabColor, PatternColor, ShadingColor, SpotColor, UncoloredPattern, and maybe even more.

    You have to identify the actual class of the returned color object and cast accordingly.