2

I issue the following command:

gs \
-o downsampled.pdf \
-sDEVICE=pdfwrite \
-dDownsampleColorImages=true \
-dColorImageResolution=180 \
-dColorImageDownsampleThreshold=1.0 \

And get the following errors:

Subsample filter does not support non-integer downsample factor (1.994360)
Failed to initialise downsample filter, downsampling aborted

(on some pages)

and:

Subsample filter does not support non-integer downsample factor (2.000029)
Failed to initialise downsample filter, downsampling aborted

Originally I tried to downsample to 150dpi, which gave the error with factor (2.40????), meaning multiple errors, where the last few digits are different for different pages. So I guessed that images are approximately 150*2.4 = 360 dpi. So I try downsampling to 180. But it seems the images are all slightly off?

  1. Is there a way to specify the factor instead of the dpi?
  2. Is there a way to "round" the factor?
Admiral Tso
  • 71
  • 2
  • 7

1 Answers1

6

No, there is no way to specify the factor (this is the Adobe specification for distiller params, we are currently limited to those). You cannot specify an approximation for rounding either, without modifying the source code.

You can use a different downsampling algorithm.

[much later]

In fact I just checked the current code, and you must be using an old version of Ghostscript.

The current default downsampling filter is the Bicubic filter, and if you do force the Subsample filter, then the code checks to see if the downsample factor requested is an integer.

If the factor is not an integer but is within 0.1 of an integer then it forces factor to the nearest integer.

If its outside 0.1 of an integer factor then it aborts the subsample filter and switches to Bicubic.

I'd recommend upgrading.

[later edit]

So avoiding the bogus ColorDownsampleOption, the problem is actually not colour images at all, its monochrome images, or more precisely in your case, imagemasks.

I set up this command line:

gs 
    -sDEVICE=pdfwrite \
    -sOutputFile=pdfwrite.pdf \
    -dDownsampleColorImages=true \
    -dDownsampleGrayImages=true \
    -dDownsampleMonoImages=true \
    -dColorImageDownsampleThreshold=1 \
    -dGrayImageDownsampleThreshold=1 \
    -dMonoImageDownsampleThreshold=1 \
    -dColorImageDownsampleType=/Bicubic \
    -dGrayImageDownsampleType=/Bicubic \
    -dMonoImageDownsampleType=/Bicubic \
    -dColorImageResolution=72 \
    -dGrayImageResolution=72 \
    -dMonoImageResolution=100 "gs sample.pdf"

And that produces an error message that the only filter available for monochrome images is Subsample, followed by the error messages you quote about the imprecise factor.

I guess basically this makes my point that an example file is pretty much vital in order to investigate problems.

So there is a problem there, and I will look into it, obviously for monochrome images it should be clamped to the nearest integer resolution, since no other filter is possible. However, Gray and Colour images do work as expected.

Reporting a bug, as I suggested in an early comment would probably have got to this point much sooner. I'd still suggest you do that, so that this is not overlooked.

You may be interested to note that, for me, the resulting file when I don't downsample monochrome images, but do downsample the others, as per the command line above, is 785KB the original being 2.5MB.

Zijian He
  • 33
  • 1
  • 3
KenS
  • 30,202
  • 3
  • 34
  • 51
  • I just upgraded to 9.20 of ghostscript from 9.19, and am still getting the error. – Admiral Tso Oct 19 '16 at 15:53
  • Well, I tried it here, obviously not using your file because you haven't posted one, and it worked for me. So either there is something interesting about your file, or your version of Ghostscript. Where did you get GS from ? We know that package maintainers sometimes modify the source and its possible a problem has crept in. I'd suggest either building yourself from source or reporting a bug, since the code isn't meant to work like that. If you report a bug don't forget to include the file and command line to reproduce the problem. – KenS Oct 19 '16 at 16:15
  • Actually, I am getting the same error even when I specify -dColorDownsampleOption=/Bicubic – Admiral Tso Nov 14 '16 at 19:37
  • There is no switch called 'ColorDownsampleOption'. What is the version of Ghostscript you are using ? Where did you get it from ? A package, source built yourself, something else ? Since you haven't supplied your own file, I obviously can't check that You haven't answered these same questions from my last comment so I can't add anything more other than to repeat what I said; I've tried this on current code myself and it works as expected. – KenS Nov 15 '16 at 07:47
  • I think the gs I have is from OS X. This is what I get for gs -v : GPL Ghostscript 9.20 (2016-09-26) Copyright (C) 2016 Artifex Software, Inc. All rights reserved. Here is a file where this error occurs: http://s000.tinyupload.com/?file_id=37816699071848940536 The command I'm using is: – Admiral Tso Nov 16 '16 at 15:57
  • gs \ -o bicubic200.pdf \ -sDEVICE=pdfwrite \ -dNOPAUSE \ -dDownsampleColorImages=true \ -dDownsampleGrayImages=true \ -dDownsampleMonoImages=true \ -dColorDownsampleOption=/Bicubic \ -dGrayDownsampleOption=/Bicubic \ -dMonoDownsampleOption=/Bicubic \ -dColorImageResolution=200 \ -dGrayImageResolution=200 \ -dMonoImageResolution=200 \ -dColorImageDownsampleThreshold=1.0 \ -dGrayImageDownsampleThreshold=1.0 \ -dMonoImageDownsampleThreshold=1.0 \ gs sample.pdf – Admiral Tso Nov 16 '16 at 15:58
  • I tried using the 'ColorDownsampleOption' based on http://www.ghostscript.com/doc/9.20/VectorDevices.htm#PDFWRITE. I found this pretty confusing and incomplete as far as documentation goes and would appreciate it if you could suggest an alternate. – Admiral Tso Nov 16 '16 at 16:03
  • That's the best there is, and its considerably improved over the previous documentation. I can't see any switch named ColorDownsampleOption mentioned on that web page, any clues ? I'd be happy to try your command line here, but there's no real point without your example file to look at as well, I already tried it with a file I have here and it worked just fine. Perhaps you could put your example file on DropBox or something. I just realised you did that in an earlier comment, I'll go fetch it and try it here – KenS Nov 16 '16 at 16:09
  • I thought I got ColorDownsampleOption from that page, but now I can't find it, I probably made a mistake. I think the one I was trying to use is Mono(\Gray\Color)ImageDownsampleType. I get a different error: The only Downsample filter for monochrome images is Subsample, ignoring request. Subsample filter does not support non-integer downsample factor (3.017893) Failed to initialise downsample filter, downsampling aborted. However, the previously linked documentation page seems to allow bicubic downsampling even for monochrome images (it is the default method for prepress). – Admiral Tso Nov 16 '16 at 16:22
  • Edited my answer as its too long for a comment. – KenS Nov 16 '16 at 16:24