Page 1 of 1
count color and grayscale pages in a PDF
Posted: Fri Nov 23, 2012 6:05 pm
by tz8
Hi,
is there an easy way with switch's own scripting capabilities to count all color and non-color pages from a document or is this out of switch's own FileStatistics capabilities?
Cheers,
Thorsten
count color and grayscale pages in a PDF
Posted: Fri Nov 23, 2012 6:39 pm
by dkelly
Hello, this is beyond the capabilities of Switch's Statistics which only collects a summary of the colors used by ALL of that PDF pages. Additionally, it only reports Separation, DeviceN, Indexed and NColor -- not the colorants used by those complex color types. For example, you can have a Separation of "Black" which is the same as DeviceGray.
Use Apago's PDFspy to get accurate color usage per page and document.
Dwight Kelly
Apago, Inc.
dkelly@apago.com
count color and grayscale pages in a PDF
Posted: Fri Nov 23, 2012 7:59 pm
by tz8
do you have an example scripting to do this? And can i actually test it with the trial version? If this would help our production process i'd happily spend the money for the PDFspy

count color and grayscale pages in a PDF
Posted: Sat Nov 24, 2012 4:37 pm
by dkelly
Yes we can provide both a trial license and some example Switch JS scripts for using PDFspy with Switch. Please send an email to
support@apago.com and we will send you the information on Monday.
count color and grayscale pages in a PDF
Posted: Sun Nov 25, 2012 9:18 pm
by dkelly
Here's a complex scripting example of using Apago's PDFspy to determine if a PDF is black only or contains any type of color. Files are sent to the "success" connection if black only (DeviceGray, Separation Black, K-only DeviceCMYK, DeviceN Black, or Indexed black). Otherwise, file is routed to the "error" connection.
// Determine if a PDF file contains black colors only.
// Copyright (C) 2012 by Apago, Inc.
// All rights reserved.
function jobArrived( s : Switch, job : Job )
{
var pdfInfo = job.getDataset("Pdf");
if (pdfInfo != null) {
var bBlackOnly = true;
var theNumberofColors = pdfInfo.evalToNumber( "count(/pdfattrs/colors/*)", null);
s.log( 1, "There are " + theNumberofColors + " colors defined in PDF");
var i;
for (i=1; i<=theNumberofColors; i++) {
var theColorValue = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/@base", null );
if (theColorValue == "Separation") {
var theSepName = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]", null );
s.log(1, "found Separation " + theSepName);
if (theSepName != "Black") {
s.log(1, "Separation " + theSepName + " isn't black");
bBlackOnly = false
}
} else if (theColorValue == "DeviceN") {
var theNumberofChannels = pdfInfo.evalToNumber( "count(/pdfattrs/colors/color[+i+]/*)", null);
var theSepName = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/color[1]", null );
s.log(1, "found DeviceN(" + theNumberofChannels + ") " + theSepName);
if (theNumberofChannels != 1 || theSepName != "Black") {
s.log(1, "DeviceN: " + theNumberOfChannels + " colors or " + theSepName + " isn't Black");
bBlackOnly = false
}
} else if (theColorValue == "ICCBased") {
var theNumberofChannels = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/@comps", null);
s.log(1, "found ICCBased(" + theNumberofChannels + ")");
if (theNumberofChannels != "1")
bBlackOnly = false;
} else if (theColorValue == "Indexed") {
var theColorValue = pdfInfo.evalToString( "/pdfattrs/colors/color[+i+]/color[1]/@base", null);
if (theColorValue == "Separation") {
var theSepName = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]", null );
s.log(1, "found Indexed Separation " + theSepName);
if (theSepName != "Black") {
s.log(1, "Separation " + theSepName + " isn't black");
bBlackOnly = false
}
} else if (theColorValue == "DeviceN") {
var theNumberofChannels = pdfInfo.evalToNumber( "count(/pdfattrs/colors/color[+i+]/color[1]/*)", null);
var theSepName = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/color[1]/color[1]", null );
s.log(1, "found Indexed DeviceN(" + theNumberofChannels + ") " + theSepName);
if (theNumberofChannels != 1 || theSepName != "Black") {
s.log(1, "DeviceN: " + theNumberOfChannels + " colors or " + theSepName + " isn't Black");
bBlackOnly = false
}
} else if (theColorValue == "ICCBased") {
var theNumberofChannels = pdfInfo.evalToNumber( "/pdfattrs/colors/color[ + i + ]/color[1]/@comps", null);
s.log(1, "found Indexed ICCBased(" + theNumberofChannels + ")");
if (theNumberofChannels != 1)
bBlackOnly = false;
} else if (theColorValue == "DeviceCMYK") {
var theUsedColors = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/color[1]/@used", null );
s.log(1, "found Indexed DeviceCMYK used="+theUsedColors);
if (theUsedColors != "K")
bBlackOnly = false
} else if (theColorValue == "DeviceGray") {
s.log(1, "found Indexed DeviceGray");
} else
bBlackOnly = false;
} else if (theColorValue == "DeviceCMYK") {
var theUsedColors = pdfInfo.evalToString( "/pdfattrs/colors/color[ + i + ]/@used", null );
s.log(1, "found DeviceCMYK used="+theUsedColors);
if (theUsedColors != "K")
bBlackOnly = false
} else if (theColorValue == "DeviceGray") {
s.log(1, "found DeviceGray");
} else
bBlackOnly = false;
}
if (bBlackOnly) {
s.log(1, "PDF contains only black");
job.sendToData( 1, job.getPath() );
} else {
s.log(1, "PDF contains color");
job.sendToData( 3, job.getPath() );
}
} else {
job.fail("No pdfspy metadata found!");
}
}