0

I am running a gs script that converts range of PDF pages into grey scale. Once complete it generates an output file by removing the pages that were not in given in the -sPageList parameter.

Does gs has an option to retain unprocessed pages? I have read through the online documentation and could not find the answer to it. man gs did not help as well.

Script

#!/bin/bash

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -sPageList=1-37,39-42,44,45,47-60,63-67,69-71,73-80,82,85-116,119,122-142,145-147,149-199,201-215,218,220,221,225,227-232,235,237,240- \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 $1
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150

1 Answers1

0

No.

The way the pdfwrite device works is described here if you process a page from the input then it reaches the output, if you don't process a page form the input then it doesn't reach the output. All options are applied to all the input pages.

So you cannot choose to only convert some pages to gray and leave the others untouched which is what I think you are actually asking for.

You could produce a gray PDF file per page, and then use a similar approach to produce one PDF file per page of untouched output. Then you could create a script which processed each individual PDF file in the order you want, to create a final PDF file with all the pages in the correct order.

Here's a simplified example, considering a 4 page file where we want to leave page 3 untouched and make the other pages gray:

First process all the gray pages:

gs \
 -sOutputFile=gray/output%d.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -sPageList=1, 2, 4 \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 input.pdf

Then produce all the other pages:

gs \
 -sOutputFile=original/output%d.pdf \
 -sDEVICE=pdfwrite \
 -sPageList=3
 -dNOPAUSE \
 -dBATCH \
 input.pdf

Then finally stitch all the pages back:

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -dNOPAUSE \
 -dBATCH \
 gray/output1.pdf gray/output2.pdf original/output1.pdf gray/output3.pdf

A sufficiently complicated (number of pages) file will overrun the line length of a shell, in whcih case you can look into the @file syntax where you put the whole command line in a file and tell Ghostscript to use the file contents for the command line.

No, you can't change the %d syntax so that the device writes the output files with the page number, that's not how the numbering works, it always starts from 1.

KenS
  • 30,202
  • 3
  • 34
  • 51