Search code examples
ghostscript

Ghostscript color converting of selected pages but output of all pages


I want to convert some pages in a PDF to grayscale I can use the ghostscript option -sPageList to select the desired pages. But the output contains only the selected pages.

How can I get the whole PDF including the converted pages?


Solution

  • You cannot do this in one pass with Ghostscript and the pdfwrite device.

    The colour conversion options are applied to all the selected output pages, so you need to start by using the PagesList to output the pages you want colour converted. You can use the '%d' format specifier to get each page as a separate file. You can then 'split' the pages you didn't colour convert from the original file by doing the 'opposite' PagesList and using %d again to get each page in a separate file.

    Now you have each page as a separate PDF file, some colour converted, some not.

    Finally you can feed Ghostscript with each of the PDF files, in the desired order, to create a new PDF file which contains all the pages in the order you want.