Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Printing envelopes with bash-script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
derverstand
Guru
Guru


Joined: 15 Dec 2005
Posts: 511
Location: /dev/null

PostPosted: Wed Jun 21, 2006 11:44 am    Post subject: Printing envelopes with bash-script Reply with quote

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
Code:

lpoptions -l


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
View user's profile Send private message
alligator421
Apprentice
Apprentice


Joined: 30 Jul 2003
Posts: 191

PostPosted: Wed Jun 21, 2006 6:19 pm    Post subject: Reply with quote

Interesting, maybe you should make it a topic in "documentation, tip &tricks".
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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