I am not quite sure of your application so I will provide a few links
you may find helpful if you need something beyond what you immediately
The best method to do what you ask can be done in a few, relatively
easy steps. If some step is not described sufficiently or is unclear -
do not hesitate to make a clarification request and I would be glad to
expand on the answer.
 Take your PS or PDF file and feed to Ghostscript to generate a PNG
file for each page. Something like:
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r150 \
will rasterize paper.ps to create a series of files paper-001.png,
paper-002.png, and so on.
Note that Ghostscript has a LOT of options so if you want color or
black and white, adjust the command line to be appropriate. See
for extensive documentation on both major versions of Ghostscript (GNU, AFPL),
for a list of supported devices (for GNU Ghostscript) or use
on your Linux system for more information on gs options / capabilities.
 Process the PNG file(s) and compute the amount of black (or color)
on each page and print out the result. I found a set of three C
programs that appear to fit the bill. They are:
- percentblack.c - computes black coverage (as a percent)
- percentcolour.c - computes color coverage (as a percent)
- percent_cmy.c - computes color for each of the three colors (as a percent)
I read through the source of these [but have not built them] and they
appear to do a good job at computing the percentages you need.
If you need cmyk, the accurate result will likely be based on some
"threshold" for black and vary by printer. Perhaps modifying
percent_cmy to compare each pixel is >250 for all three colors would
be a good compromise (instead of using 255 for each) but I am not
sure. If you make this change, be sure to not "double" count the
pixels that are black. Make a clarification request if you need the
coding for this change.
To get these programs, download "printbill" from Debian (a Linux
distribution) and build the three files in the "src" directory (after
expanding the tar file). Something like
tar xzf printbill_4.1.2-1.tar.gz
should do the bill. [though if you need to debug one of the programs,
I suggest not stripping the binaries before attempting to debug them -
let me know if you want this explained]
I am not sure if "printbill" is currently maintained but it is free
software. The Debian bug list has a few bugs, all about 2 years old.
The Freshmeat entry has also been removed. Search using a phrase like
to bring up pages describing the application. The site in Australia
where the author maintained several pages (search with)
did not respond to my inquries; use the Google cache to see the HOWTO
and other documents.
 A simple script that should process the files created in step 1
and run the program in step 2 could be as simple as:
for N in *.png ; do
(assuming percent_cmy is in your PATH - if not, use the full path)
on your Linux system or
for more information on the "Bourne Again Shell".
If you are trying to bill based on ink usage, I suggest using
printbill directly. The HOWTO in particular describes the set up for
Debian as well as describing the steps for a Red hat system.
There was also a nice comparison between billing applications I found at
if you want some other alternatives for comparison. [it was this
article that lead me to printbill and the source code to analyze
This information should be sufficient to do what you asked for
directly. If you need something a little different or are having
problems with the download or build of the application - please make a
clarification request. I would be glad to help further.