[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(A possible) way to change the background color of pdf

From: Hans Bezemer
Subject: (A possible) way to change the background color of pdf
Date: Tue, 15 Jun 2021 11:29:37 +0200

Dear all,

I want to have a black background with green text for my

If I'm correct this can't be set within groff.

I've created a script to post process the pdf to add the
desired background color.

This is my sample document:
cat GreenText.groff

.gcolor green
Green text
More Green text on page 2
Green on 3
Green on 4
Green on 5
Green on 6
Green on 7
Green on 8
Green on 9
Green on 10

The scripts adds a background color per page (It doesn't
seem to be able to add it on a multipage pdf directly) and
the separate pages with the added background color are

cat <filename> <backgroundcolor>

# Script to convert background of pdf to color specified by $2
# Get the name without extension
NAME=$(echo $1 | cut -d "." -f 1 )
# Get the number of pages
PAGES=$(pdfinfo $1 | grep Pages | rev | cut -d " " -f 1 | rev)
# Get the max number of pages from number of pages
DIGMAX=$(echo -n $PAGES | wc -c )
# Convert page by page and making sure that if i is > 10 the numbering of the 
# files are still correct.
for i in $(seq 1 $PAGES)
        DIGI=$(echo -n $i | wc -c)
        for k in $(seq 1 $DIFFDIG)
        convert -density 300 $1[$j] -background $2 -flatten -quality 100 
        unset ZEROI
# Merge the temp pdfs to one.
pdfunite Temp${NAME}*.pdf ${NAME}${2}.pdf
# Delete temp files.
rm -fv Temp${NAME}*.pdf
#End Of File

Please let me know if there are better solutions available
but this seems to work for now.

Kind regards,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]