Hello Smsimms,
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
ask for.
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.
[1] 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 \
-sOutputFile='paper-%00d.png' paper.ps
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
http://www.cs.wisc.edu/~ghost/doc/index.htm
for extensive documentation on both major versions of Ghostscript (GNU, AFPL),
http://www.gnu.org/software/ghostscript/devices.html
for a list of supported devices (for GNU Ghostscript) or use
man gs
or
info gs
or
gs -h
on your Linux system for more information on gs options / capabilities.
[2] 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
wget http://ftp.debian.org/debian/pool/main/p/printbill/printbill_4.1.2-1.tar.gz
tar xzf printbill_4.1.2-1.tar.gz
cd printbill_4.1.2-1/src
make
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
printbill Debian
to bring up pages describing the application. The site in Australia
where the author maintained several pages (search with)
site:uow.edu.au printbill
did not respond to my inquries; use the Google cache to see the HOWTO
and other documents.
[3] A simple script that should process the files created in step 1
and run the program in step 2 could be as simple as:
$!/bin/sh
for N in *.png ; do
percent_cmy $N
done
(assuming percent_cmy is in your PATH - if not, use the full path)
Refer to
man bash
on your Linux system or
http://www.cs.sunysb.edu/documentation/bash/bash.html
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
http://www.librelogiciel.com/software/PyKota/pykota-vs-printbill-vs-printquota-vs-pquotas.html
if you want some other alternatives for comparison. [it was this
article that lead me to printbill and the source code to analyze
PNG's]
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.
--Maniac
µ |