pdfghostscriptpdf-conversion

When converting a PDF to a lower-resolution PDF file with Ghostscript, the background black colour is applied to the text and icons


When converting a PDF to a lower-resolution PDF file with Ghostscript, the background black colour is applied to the text and icons.

enter image description here

Download original PDF file

My code:

gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dDownsampleColorImages=true -dColorImageResolution=72 -dColorImageDownsampleThreshold=1.0 -dDownsampleGrayImages=true -dGrayImageResolution=72 -dGrayImageDownsampleThreshold=1.0 -dDownsampleMonoImages=true -dMonoImageResolution=72 -dMonoImageDownsampleThreshold=1.0 -dHaveTransparency=false -sProcessColorModel=DeviceRGB -sColorConversionStrategy=RGB -sColorConversionStrategyForImages=RGB -dTransferFunctionInfo=/Apply -sOutputFile=output.pdf input.pdf


Solution

  • If we simply isolate one image and apply the switch between transparency=false and transparency=true we can see the difference that will affect PDF images with transparency. This is common to many PDF handlers since PDF defines transparency as levels of soft Mask and full transparency is stored as if image has a black value!

    enter image description here

    The way colours are stored in a PDF is as a bitmap so take this simplest of samples enter image description here

    7 0 obj<</Length 27/Type/XObject/Subtype/Image/Width 3/Height 3/BitsPerComponent 8/SMask 5 0 R/ColorSpace/DeviceRGB>>
    stream
    ÿ   ÿ   ÿ ÿÿÿ ÿÿÿ    ÿÿÿ   
    endstream
    

    If we split the colour into 3 parts for each row we can see the text pattern.

    ÿ   ÿ   ÿ
     ÿÿÿ ÿÿÿ 
       ÿÿÿ   
    

    Note that the bottom row which has a first RGB colour as transparent white is the same on the left as the right which looks black (actually neither is black or white simply 3 x null but here as a space character).

    When we look at the transparency component it may look like this.

    5 0 obj <</Length 4/Type/XObject/Subtype/Image/Width 3/Height 3/BitsPerComponent 1/ColorSpace/DeviceGray>>
    stream
    ÿÿÿ
    endstream
    

    enter image description here and if we remove that transparency object (here we set the 5th index to just hidden) the image will change from white to black, where the transparent white was.

    enter image description here