以下を使用して、文字列から固定サイズのPDFファイル(A4)を生成する小さなシェル関数を作成しました。gs
:
make_stamp() {
file=$1
string=$2
tmp=${file}-small.pdf
gs -o "$tmp" -sDEVICE=pdfwrite -g500x200 \
-c "/Helvetica findfont 12 scalefont setfont" \
-c "0 1 0 0 setcmykcolor" \
-c "0 5 moveto" \
-c "(${string}) show" \
-c "showpage"
gs -o "$file" -sDEVICE=pdfwrite -g5950x8420 \
-c "<</PageOffset [510 20]>> setpagedevice" \
-f "$tmp"
}
しかし、改善したいことがいくつかあります。
- 作成時にモノクロ背景を設定する方法は
$tmp
? - を作成するときに
$tmp
テキストの周りにぴったり合うようにサイズを自動的に計算できますか?一部はpt
パディングとして使用できますか? - この関数を一度だけ呼び出すようにオーバーライドできますか
gs
?
または
- 直接動作しない他の方法はありますか
gs
?インプリントファイルはテキストでなければならず、レンダリングされたイメージは良くありません。
$stamp
興味のある方のために、次の呼び出しでこの関数の出力を使用しますpdftk
。
pdftk original.pdf stamp $stamp output stamped.pdf
ベストアンサー1
私は最近PDF "Bates-stamping"スクリプトを書いた法的問題に関与していますpdfBatesStamp.sh
。
使い方抜粋
# "Bates-stamp" a PDF file with text (only; images aren't supported). Uses
# ghostscript (ps2pdf) and pdftk.
#
# The output (Bates-stamped) file is put in the same directory, with "_BATES"
# appended to its name, thusly:
# pdfBatesStamp.sh <FILE>.pdf ==> <FILE>_BATES.pdf
#
# Usage:
# pdfBatesStamp.sh <FILE>.pdf [PREFIX(def=<FILE>)] [STARTNUM(def=1)]
# pdfBatesStamp.sh <FILE>.pdf BATESCONFIG=<bates_config_filename>
#
# The <FILE>.pdf name must end in ".pdf". You can make many more settings
# inline below (you can also set PREFIX and STARTNUM there too if you want).
# The first invocation format above is for the most common case (e.g., for legal
# use). In the second invocation format, the <bates_config_filename> file can
# contain any of the inline user-settings (below, from PREFIX to EXTRAS,
# inclusive), and they will overwrite the inline settings. In this way, you can
# write/store special config file settings for special PDFs, without needing to
# modify the inline settings each time. Runs at ~3 pages/sec.
フルスクリプトはPastebinからダウンロードできます。pdfBatesStamp.sh。