View previous topic :: View next topic |
Author |
Message |
derverstand Guru
Joined: 15 Dec 2005 Posts: 511 Location: /dev/null
|
Posted: Wed Jun 21, 2006 11:44 am Post subject: Printing envelopes with bash-script |
|
|
Hi,
Here a small sniplet from my .profile for printing envelopes. At this time it is working with a HP LasetJet4... But it should work with other printers by adjusting printername and paperformats. You may find out the paperformats with
To adjust: ADDRESSER_..., ENVELOPE_PRINTER, PAGESIZE
Code: |
function envelope {
local ADDRESSER_NAME="Your name here"
local ADDRESSER_STREET=""
local ADDRESSER_CITY=""
local ADDRESSER_COUNTRY=""
if [ -z $4 ]; then
echo "envelope <format:c5|c6|dl|a4> <name // street // city (// country)>"
echo "c5: a4 folded in 1/2 c6: a4 folded in 1/4 dl: a4 folded in 1/3 a4"
return -1
fi
local ENVELOPE_PRINTER="LJ5envelope"
local TMPFILE="/tmp/envelope"
local PAPERSIZE=$1
local CURDATE=`date`
shift
# Split receiver data
local RECEIVER=`echo $@ | sed 's/ *\/\/ */\/\//g'`
local RECEIVER_NAME=`echo $RECEIVER | awk '{split($0,a,"//"); print a[1]}'`
local RECEIVER_STREET=`echo $RECEIVER | awk '{split($0,a,"//"); print a[2]}'`
local RECEIVER_CITY=`echo $RECEIVER | awk '{split($0,a,"//"); print a[3]}'`
local RECEIVER_COUNTRY=`echo $RECEIVER | awk '{split($0,a,"//"); print a[4]}'`
# Paper format
if [[ $PAPERSIZE == c6 ]]; then
local MAXX=459
local MAXY=323
local PAGESIZE="EnvC6"
elif [[ $PAPERSIZE == c5 ]]; then
local MAXX=649
local MAXY=459
local PAGESIZE="EnvC5"
elif [[ $PAPERSIZE == dl ]]; then
local MAXX=624
local MAXY=312
local PAGESIZE="EnvDL"
elif [[ $PAPERSIZE == a4 ]]; then
local MAXX=842
local MAXY=595
local PAGESIZE="A4"
fi
# Definitions
cat << EOF >> $TMPFILE
%!PS-Adobe-1.0
%%Title: Envelope
%%Creator: test
%%CreationDate: $CURDATE
%%DocumentFonts: Times-Roman
%%DocumentPaperSizes: $PAPERSIZE
/maxx $MAXX def
/maxy $MAXY def
/margin 20 def
/fontsize_small 8 def
/fontsize_big 12 def
/address_x maxx fontsize_big 17 mul sub def
/address_y maxy margin fontsize_big 4 mul add sub def
/sender_x margin def
/sender_y margin 8 add def
/newline_small {
currentpoint fontsize_small sub
exch pop
sender_x exch
moveto
} def
/newline_big {
currentpoint fontsize_big sub
exch pop
address_x exch
moveto
} def
/sender {
gsave
/Helvetica findfont
fontsize_small scalefont
setfont
sender_y sender_x moveto
90 rotate
(Sender: ) show
newline_small
($ADDRESSER_NAME) show
(, ) show
($ADDRESSER_STREET) show
newline_small
($ADDRESSER_CITY) show
(, ) show
($ADDRESSER_COUNTRY) show
grestore
} def
/address {
gsave
/Helvetica findfont
fontsize_big scalefont
setfont
address_y address_x moveto
90 rotate
($RECEIVER_NAME) show
newline_big
($RECEIVER_STREET) show
newline_big
($RECEIVER_CITY) show
newline_big
($RECEIVER_COUNTRY) show
grestore
} def
sender
address
showpage
EOF
# Print it
lpr -P$ENVELOPE_PRINTER -o Manualfeed=On -o PageSize=$PAGESIZE $TMPFILE
rm $TMPFILE
}
|
Maybe somebody finds it useful... Best regards! |
|
Back to top |
|
|
alligator421 Apprentice
Joined: 30 Jul 2003 Posts: 191
|
Posted: Wed Jun 21, 2006 6:19 pm Post subject: |
|
|
Interesting, maybe you should make it a topic in "documentation, tip &tricks". |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|