Author Topic: Script to count how many colour pages in PDF?  (Read 980 times)

0 Members and 1 Guest are viewing this topic.

nightslayer23

  • Newbie
  • *
  • Posts: 35
Re: Script to count how many colour pages in PDF?
« Reply #15 on: July 19, 2017, 08:16:14 AM »
Is there a way for the file to be flattened first before doing this conversion? Some work perfectly, but others come out at a really high percentage when they aren't technically going to print that way. I figured it was looking at other layers or some other hidden info and converting that to bw too.
Are these trouble PDF layers set to be visible in the PDF reader (screen mode) and hidden when printed? If that's the case, edit the file delegates.xml, where you have ImageMagick installed, and change the line "<delegate decode="ps:alpha" stealth="True" command="&quot;@PSDelegate@&quot; -q -dQUIET -..." to include the -dPrinted parameter.

Quote
So would i be possible in code to first flatten layers before running the check?
When the ImageMagick tool calls the Ghostscript to convert each of the PDF pages to an image, that then uses to run the color check, is effectively flattening the PDF. If the issue is not the mentioned above (these layers are set to be hidden only when the PDF is printed) and even hidden layers are being rendered too, then that's an issue with Ghostscript.
If you have Acrobat, I suppose the script can automate it to flatten the PDF layers to a temporary PDF file and then run the check on that PDF.

Quote
I actually batch flattened layers in acrobat and it didn't solve the issue.. I had to batch flatten AND convert everything to CMYK to get it to work.
Can't opine without a sample file.

Quote
In the optimizer tool, can CMYK and RGB colour spaces be added somehow?
I'm not understanding your question. Please explain this better.

They view hidden as well. but I'm assuming that's why they come out saying an extremely high percentage.. because once I render the file, goes from saying 75% & 99% to 12% and 22% for example - which is how they view as well.

RTT

  • Administrator
  • *****
  • Posts: 778
Re: Script to count how many colour pages in PDF?
« Reply #16 on: July 20, 2017, 12:01:52 AM »
Did you tested with the -dPrinted parameter I suggested in my previous reply?

You can easily verify if indeed the hidden layers are being erroneously rendered. From a command prompt, run (change the file paths to your system specifics):
"C:\Program Files (x86)\ImageMagick-7.0.5-Q16\magick.exe" convert "Path\To\The\PDF.pdf" "Path\Where\To\Put\The\Page\Renders\Image.png"

You can also check what image is being generated in the script, to quantify the ink utilization:
"C:\Program Files (x86)\ImageMagick-7.0.5-Q16\magick.exe" convert "Path\To\The\PDF.pdf" -colorspace gray -auto-level -threshold 99% "Path\Where\To\Put\The\Page\Renders\Image.png"