在tcl的wiki上printing under windows一节看到ezprint这个扩展。
ezprint是一个用于在windows(Windows NT/2000/XP)下支持打印功能的扩展。它可以获得当前安装的打印机列表和默认打印机并把文件以raw data的格式发送给本地和网络打印机。
Loading the ezprint extension adds a single command "ezprint" to the Tcl interpreter. The following subcommands are defined:
ezprint listprinters
Returns a list of the names of available printers.
Throws a Tcl error if something goes wrong.
ezprint defaultprinter
Returns the name of the default printer.
On error, returns an empty string.
ezprint open $printername ?options?
Opens a connection to the named printer. Returns a Tcl channel which you can use to send
data to the printer.
Options:
-jobname NAME Name the job in the spooler
If you don't name the job, it just gets called "Print".
ezprint abort $channel
Aborts the print job open on the named channel (which was returned by [ezprint open]). Nothing will be printed. Caller must still close the channel.
Once a connection to the printer is open, you can use [puts] to send data, and [close] to close the connection and spool the print job. You can use [fconfigure] to change translation and buffering. No other I/O operations are available on the channel.
You should turn off automatic translation when writing raw data to a printer, especially if the data could contain control characters or null bytes. See example below.
Examples:
# Send a file "report.pcl" to the default printer:
load ezprint.dll
set f [open report.pcl]
fconfigure $f -translation binary
set p [ezprint open [ezprint defaultprinter]]
fconfigure $p -translation binary
puts -nonewline $p [read $f]
close $p
close $f
# Make an option menu list of all available printers, with the
# user's default printer selected:
global selected_printer
...
set selected_printer [ezprint defaultprinter]
eval tk_optionMenu $widgetname selected_printer [ezprint listprinters]
...
没有评论:
发表评论