groff
[Top][All Lists]
Advanced

[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
slides.

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
.bp
More Green text on page 2
.bp
Green on 3
.bp
Green on 4
.bp
Green on 5
.bp
Green on 6
.bp
Green on 7
.bp
Green on 8
.bp
Green on 9
.bp
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
merged.

cat ConvertBackground.sh <filename> <backgroundcolor>

#!/bin/sh
# 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 
temp
# files are still correct.
for i in $(seq 1 $PAGES)
do
        j=$(($i-1))
        DIGI=$(echo -n $i | wc -c)
        DIFFDIG=$(($DIGMAX-$DIGI))
        for k in $(seq 1 $DIFFDIG)
        do
                ZEROI="${ZEROI}0"
        done
        convert -density 300 $1[$j] -background $2 -flatten -quality 100 
Temp${NAME}${ZEROI}${i}.pdf
        unset ZEROI
done
# 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,

Hans



reply via email to

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