Hi,
Ghostscript device called inkcov can detect whether a PDF page uses color or not. It displays the ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally).
I wrote you a small routine that will return you ink coverage for each page:
C (cyan) M (magenta) Y (yellow) K (black)
0.00000 0.00000 0.00000 0.01721 CMYK OK
0.00000 0.00000 0.00000 0.03788 CMYK OK
0.00000 0.00000 0.00000 0.04137 CMYK OK
0.00000 0.00000 0.00000 0.00621 CMYK OK
0.00000 0.00000 0.00000 0.01462 CMYK OK
0.00000 0.00000 0.00000 0.01103 CMYK OK
Where a value of 1.00000 maps to 100% ink coverage for the respective color channel. So 0.01721 in the first line of the result means 1.72 % of the first page area is covered by black ink.
I hope this helps.
Cheers,
Josip
Ghostscript device called inkcov can detect whether a PDF page uses color or not. It displays the ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally).
I wrote you a small routine that will return you ink coverage for each page:
/// <summary>
/// Supported only in Ghostscript v9.05 or newer.
/// </summary>
public static string GetInkCoverage(string file)
{
GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-q");
switches.Add("-o" + outputPipeHandle);
switches.Add("-sDEVICE=inkcov");
switches.Add(file);
GhostscriptProcessor proc = new GhostscriptProcessor();
proc.StartProcessing(switches.ToArray(), null);
byte[] data = gsPipedOutput.Data;
return System.Text.Encoding.ASCII.GetString(data);
}
So, for PDF with 6 pages you will get the output similar to this one:C (cyan) M (magenta) Y (yellow) K (black)
0.00000 0.00000 0.00000 0.01721 CMYK OK
0.00000 0.00000 0.00000 0.03788 CMYK OK
0.00000 0.00000 0.00000 0.04137 CMYK OK
0.00000 0.00000 0.00000 0.00621 CMYK OK
0.00000 0.00000 0.00000 0.01462 CMYK OK
0.00000 0.00000 0.00000 0.01103 CMYK OK
Where a value of 1.00000 maps to 100% ink coverage for the respective color channel. So 0.01721 in the first line of the result means 1.72 % of the first page area is covered by black ink.
I hope this helps.
Cheers,
Josip