2

I know this question has been asked before but it doesn't explain much and as I don't have a reputation to comment there I am asking this question.

The answer that was provided in the aforementioned thread retrieves the r g and b values but I don't know what tells if the values that are found show what part is CMYK (as I understand that after rendering all values are converted into RGB).

I need to first identify what color system is used in a pdf file, I understand now that CMYK and RGB can be simultaneously used in a single file. So I need to analyze the pdf file in my C# application and find a way to convert the CMYK parts to RGB if need be.

I learned that conversion can be done using ABCDpdf.

Community
  • 1
  • 1
Hammadzafar
  • 480
  • 1
  • 7
  • 21
  • Maybe you can use anothe library? In this case look at example below: [Extracting images from Pdf file using .Net c#](http://pdfium.patagames.com/help/html/06ea516e-df6b-4576-abd9-1acba4426a66.htm) Note that each PdfBitmap contains information about color format: [BitmapFormats Enumeration](http://pdfium.patagames.com/help/html/1cbfa8fd-2fcd-5fce-b146-8ac6b58e677d.htm) – Andrew Jul 04 '15 at 23:44
  • Im trying PDFBitmap at the moment, ill tell you how it goes. – Hammadzafar Jul 06 '15 at 14:37

1 Answers1

0

This is a very broad question and it would be better for you if you read at least part of the PDF specification. To give you a taste of why I'm saying this...

PDF and color spaces

1) PDF can contain a wide range of color spaces
- Device color spaces such as RGB, CMYK and Gray
- Abstract color spaces such as Lab
- ICC profile based color spaces such as ICC-based RGB, ICC-based Lab, ...
- Named or special color spaces such as Separation, Device-N and N-Channel
(and I'm omitting some charming ones such as patters and shadings)

2) All of the above color spaces can be used throughout a single PDF file. When your PDF file is compliant to certain ISO standards (such as PDF/A, PDF/X...) it has to obey rules that restrict the number of color spaces, but in general all color spaces are allowed in a single PDF.

3) Where a PDF file is used determines how these color spaces need to be handled. If you want to print to a desktop printer with CMYK inks, something is going to convert all of these color spaces to CMYK. If you're viewing the PDF file on screen, something is going to convert all of these color spaces to RGB.

Converting colors

Yes, you can convert from CMYK (and all of these other color spaces I mentioned) to RGB. But that is also much more difficult that it may sound if you want to do it correctly. As an example have a look at this site: http://www.rapidtables.com/convert/color/cmyk-to-rgb.htm

It contains quick and easy to use formulas for this conversion:
R = 255 × (1-C) × (1-K)
G = 255 × (1-M) × (1-K)
B = 255 × (1-Y) × (1-K)

This will work, but in practice you need an engine (such as for example LittleCMS) that uses ICC Profiles (used to characterise color spaces) to do a proper conversion.

David van Driessche
  • 6,602
  • 2
  • 28
  • 41
  • thanks your conversion formula really helps. but the thing is i need to first identify which objects in pdf are cmyk and which are rgb or grayscale. I havent found any solution anywhere, I understand different color spaces and their needs but I dont understand how i can identify these schemes in a pdf – Hammadzafar Jul 05 '15 at 14:02
  • "it would be better for you if you read at least part of the PDF specification" Have you done this? It's not magic - it's all very clearly defined in the PDF specification. There's a chapter specifically on color spaces in there. – David van Driessche Jul 05 '15 at 22:24