| From 48f9f994322c808ba2e9d0db6f3ff81caf8c0b72 Mon Sep 17 00:00:00 2001 |
| From: sobhaniiest <sobhaniiest@gmail.com> |
| Date: Fri, 3 May 2019 20:53:47 +0530 |
| Subject: [PATCH] pdftops: Force monochrome/grayscale PostScript output if job |
| is to be printed in monochrome/grayscale. |
| |
| --- |
| filter/pdftops.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- |
| 1 file changed, 45 insertions(+), 1 deletion(-) |
| |
| diff --git a/filter/pdftops.c b/filter/pdftops.c |
| index 84b2b6e3..424da2e4 100644 |
| --- a/filter/pdftops.c |
| +++ b/filter/pdftops.c |
| @@ -304,6 +304,7 @@ main(int argc, /* I - Number of command-line args */ |
| wait_pid, /* Process ID from wait() */ |
| wait_status, /* Status from child */ |
| exit_status = 0; /* Exit status */ |
| + int gray_output = 0; /* Checking for monochrome/grayscale PostScript output */ |
| char *pdf_argv[100], /* Arguments for pdftops/gs */ |
| pstops_path[1024], /* Path to pstops program */ |
| *pstops_argv[7], /* Arguments for pstops filter */ |
| @@ -587,6 +588,38 @@ main(int argc, /* I - Number of command-line args */ |
| log_command_line("rastertops", rastertops_argv); |
| } |
| |
| + /* |
| + * Force monochrome/grayscale PostScript output |
| + * if job is to be printed in monochrome/grayscale |
| + */ |
| + if (ppd->color_device == 0) /* Monochrome printer */ |
| + gray_output = 1; |
| + else /*Color Printer - user option for Grayscale */ |
| + { |
| + if ((val = cupsGetOption("pwg-raster-document-type", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("PwgRasterDocumentType", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("print-color-mode", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("PrintColorMode", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("color-space", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("ColorSpace", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("color-model", num_options, |
| + options)) != NULL || |
| + (val = cupsGetOption("ColorModel", num_options, |
| + options)) != NULL) |
| + { |
| + if (strcasestr(val, "Black") || |
| + strcasestr(val, "Gray") || |
| + strcasestr(val, "Mono")) |
| + gray_output = 1; |
| + } |
| + } |
| + |
| /* |
| * Build the command-line for the pdftops, gs, pdftocairo, or |
| * acroread filter... |
| @@ -612,7 +645,13 @@ main(int argc, /* I - Number of command-line args */ |
| # endif /* HAVE_GHOSTSCRIPT_PS2WRITE */ |
| pdf_argv[7] = (char *)"-dShowAcroForm"; |
| pdf_argv[8] = (char *)"-sOUTPUTFILE=%stdout"; |
| - pdf_argc = 9; |
| + if (gray_output == 1) /* Checking for monochrome/grayscale PostScript output */ |
| + { |
| + pdf_argv[9] = (char *)"-sColorConversionStrategy=Gray"; |
| + pdf_argc = 10; |
| + } |
| + else |
| + pdf_argc = 9; |
| } |
| else if (renderer == PDFTOCAIRO) |
| { |
| @@ -851,6 +914,11 @@ main(int argc, /* I - Number of command-line args */ |
| pdf_argv[pdf_argc++] = resolution; |
| fprintf(stderr, "DEBUG: Using image rendering resolution %d dpi\n", res); |
| #endif /* HAVE_POPPLER_PDFTOPS_WITH_RESOLUTION */ |
| + if (gray_output == 1) /* Checking for monochrome/grayscale PostScript output */ |
| + { |
| + pdf_argv[1] = (char *)"-level1"; |
| + pdf_argv[pdf_argc++] = (char *)"-optimizecolorspace"; |
| + } |
| pdf_argv[pdf_argc++] = filename; |
| pdf_argv[pdf_argc++] = (char *)"-"; |
| } |