Home > Software engineering >  Permanently change the background color of a pdf book from white to a gentle grey
Permanently change the background color of a pdf book from white to a gentle grey

Time:05-28

I'm reading a 800-page PDF book, and the white background color burns my eyes. I want to give it a grey shade, for instance this background color.

I'm looking to modify the file, as opposed to using a viewer that can adjust reading colors, because I already have a preferred viewer.

I found enter image description here

Works in version 3.3.3 but a short term issue with command line affects 3.4.0/1 (should be working again in 3.4.2 onward)

-set-color-range < text-hexcolor > < background-hexcolor > so at end of a shortcut such as "C:\Program Files\SumatraPDF\SumatraPDF.exe" -set-color-range #------ #------

For natural colours you start with

-set-color-range #000000 #ffffff

For muted background colour you start with

-set-color-range #000000 #c0c0c0

enter image description here

But it will alter the full colour gamut. You can also use hotkey i to invert them.

enter image description here

Another 2 advanced background options are available for outside page boundary too.

CodePudding user response:

You can use a BeginPage procedure with Ghostscript to initially fill the page with a colour, and then render the page contents. If you use the pdfwrite device as the output device then you can create a new PDF file where the background is non-white.

Make a text file on disk (eg gray.ps) with this content

%!
<<
/BeginPage
{
pop
0.9 setgray
0 0
currentpagedevice /PageSize get
aload pop rectfill
}
>> setpagedevice

Then invoke Ghostscript like this:

gs -sDEVICE=pdfwrite -o out.pdf gray.ps in.pdf

You should find that 'out.pdf' has the same content as in.pdf, but the page background is now a light gray. For a darker gray change the value of setgray from 0.9, 0 = black, 1.0 = white.

As I said, if the PDF file does something such as filling the entire page with white this will defeat the background painting, because it will overwrite the background. But I suspect that would defeat any trickery with viewer backgrounds too.

The resulting PDF in this case will work with any viewer since the PDF file now has the background 'built in'.

  • Related