LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Creating a print script (https://www.linuxquestions.org/questions/linux-newbie-8/creating-a-print-script-609096/)

tkinsella 12-25-2007 06:47 PM

Creating a print script
 
I am fairly new to linux and I would like to create a script that will print a file when entered into the terminal.

ie) # pprint file
this command would print "file" to the printer specified in the script with the formating specified.
I would like the script to format the file in 2 columns, with borders and line numbers. i would like a head that specifies when the file was printed and the name of the file.

Is this possible? Does this make sense?
Thanks!!!!

tom

bigrigdriver 12-25-2007 07:41 PM

I beleive the command-line utility enscript can do all that. See the man page for enscript for command parameters.

tkinsella 12-26-2007 11:18 AM

Hm.... enscript comes back unknown...... any other ideas? Thanks!

joel2001k 12-26-2007 12:30 PM

perhaps a2ps
 
for scripting within bash look at http://www.tldp.org/LDP/abs/html/index.html

`lp` or `lpr` sends print requests to print spooler probably you want to install a2ps, ghostscript and so on, if you don't know how to write postscript

some useful commands for scripting

`head`, `tail`, `read`, `echo` ...

an example using html (for web standarts look at w3c.org), you could use xml and use `xsltproc` to convert it to html, maybe you want use redirections (pipes) - for faster execution

#!/bin/sh

file_in=()
file_out=()
file_ps=()
file_head=()
file_tail=()
wc_out=()
byte_count=()
byte_count_stop=()
current_matrix_row=()
sign0=()
sign1=()

function matrix_row{
current_matrix_row=`printf "<tr><td>%s</td><td>%s</td></tr>" $sign0 $sign1`
}

file_in=`read -p "read from file: "`
file_out=`read -p "write to file: "`
file_ps=`read -p "postscript file name: "`

file_head="<html><head></head><body><table>"

wc_out=`wc -c`
byte_count_stop=`expr match $wc_out "[0-9]*."`

[ byte_count_stop-1 ]
byte_count_stop=$?

byte_count=${wc_out:0:$byte_count_stop}

file_tail="</table></body></html>"

echo -e "$file_head\n" > $file_out

# here you may write some special code

echo -e "$file_tail\n" > $file_out

html2ps $file_out -o $file_ps
lp $file_ps

pwc101 12-26-2007 01:00 PM

Quote:

Originally Posted by tkinsella (Post 3001432)
this command would print "file" to the printer specified in the script with the formating specified.
I would like the script to format the file in 2 columns, with borders and line numbers. i would like a head that specifies when the file was printed and the name of the file.

Check out a2ps. If you have a postscript printer, it takes an ascii text files, generates a postscript file and sends it to the printer.

There are various options to prettify the layout, but by default it generates two column, landscape pages, with a header containing the filename, the person that printed it, the number of pages and possibly the date (can't quite remember). You can specify the --line-numbers=1 option to get it to prefix each line with its line number. See the man page for more details.

a2ps might not be installed by default, so use your package manager to add it. The same advice applies to enscript - just because it says unknown command, doesn't mean you can't add it!

makyo 12-26-2007 05:26 PM

Hi.

I have used these all upon occasion, but they are rarely all installed by default ... cheers, makyo
Quote:

mpage (1) - print multiple pages per sheet on PostScript printer
a2ps (1) - format files for printing on a PostScript printer
trueprint (1) - print program listings on postscript printer.
enscript (1) - convert text files to PostScript, HTML, RTF, ANSI, and overstrikes

tkinsella 12-27-2007 03:17 AM

Thank you all soooo much! This is what I needed! Yeah, I looked at my distro CD and found the enscript stuck on there :P The way the answer was worded made me think that it is there or it isn't and I didn't know where to go. Thanks all!!!


All times are GMT -5. The time now is 04:44 AM.