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

Re: cups-pdf



Hi again.
I think i've something that could work.

First, i've found the better tool to do the job: pdftk.
It could modify a pdf file with a background pdf as watermark.

I've write down this simple script (called watermark_pdf):

---------------------------------------------------------------------------------
#!/bin/bash
#21/06/2007 by Mirco Piccin aka pictux - pictux@gmail.com
#if your works better (surely), please send me it!! :-)

LOGDIR=/var/log/cups
LOGFILE=$LOGDIR/watermark_pdf.log

if [ `echo $2 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
  then
    echo `date` " - ERR: This scripts accepts only PDF format as input file!!! ($2)" >> $LOGFILE 2>&1
    exit 1
fi

if [ `echo $1 | grep -ce "\.[Pp][Dd][Ff]"` -le 0 ]
  then
    echo `date` " - ERR: Background/Watermark image must be in PDF format!!! ($1)"  >> $LOGFILE 2>&1
    exit 1
fi

MOVE=`which mv`
PDFTOOL=`which pdftk`
BASENM=`which basename`
FILENAME=`$BASENM $2`

$MOVE $2 /tmp/$FILENAME

echo `date` " - Executing :  /usr/bin/pdftk /tmp/$FILENAME background $1 output $2"  >> $LOGFILE 2>&1

$PDFTOOL /tmp/$FILENAME background $1 output $2
---------------------------------------------------------------------------------------------------------

i put it into /usr/local/bin and chmod-ed it to enable its execution.
It accepts 2 parameters:
- the background pdf file
- the pdf file in which apply the background pdf file (the printed file name)

So, in the /etc/cups/cups-pdf.conf 'PostProcessing' section i write:
...
PostProcessing /usr/local/bin/watermark_pdf  my_background_file.pdf
....

The second parameters (the printed file name) is passed directly from cups-pdf.
It will permit you to use print all your documents with a watermark.

If you need more explanations about the scripts above, let me know.
It also writes a log file (for now writes to log if executed manually, probably some problem of authorization...), so you can check if works good, there's also some input controls (no parameters / no pdf files).

If you print images, probably no watermark will be applied.

Hope it help you!
Bye


Reply to: