Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Idea wanted: printing with TCL/TK

275 views
Skip to first unread message

Peter Bauer

unread,
Aug 26, 2006, 11:02:33 AM8/26/06
to
Hi Folks,

I'm a beginner in TCL/TK, and I'm looking for an idea how to issue a print
reqest with TCL/TK.

My job is to write a frontend for a database application, and users need to
be able to print reports. Can you point me to a direction how I could solve
this? If possible, the print should be somewhat graphical (invoices, need to
print some lines).

Thank you!

Peter


Gerald W. Lester

unread,
Aug 26, 2006, 11:39:13 AM8/26/06
to

Which OS?

Unfortunately, do the differences in how OSes handle print systems there is
not one easy answer.

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

stephan...@yahoo.fr

unread,
Aug 26, 2006, 11:52:48 AM8/26/06
to
Peter Bauer a écrit :

> I'm a beginner in TCL/TK, and I'm looking for an idea how to issue a print
> reqest with TCL/TK.

Hi,

I did an application in Tcl/Tk which print some kind
of graphical reports.
For this I used the canvas postscript export at the first time.
As I ran it under Linux, EPS files were great. But, on my distro,
KDE raised an alert because of the EPS format that wasn't
sympathic. It seemed like modern Linux don't like EPS.

Then I thought I may want to run it under different OSes,
so I came to PDF. I tried 'Trampoline!' which exports
the content of a canvas, but it did not work for what I wanted.

Finally I grabbed 'pdf4tcl' and since then, had no problems,
did not need Tk anyway because my application is much
more UNIX-like and can run under a terminal.

Printing with PDF format is quite easy. I feel sorry I am not
a Windows expert, but there should be a way to print
PDF files on the disk with a command or an extension.

Hopes it helps !

Cheers,
Stéphane

Cameron Laird

unread,
Aug 26, 2006, 8:12:02 PM8/26/06
to
In article <1156607568.5...@m73g2000cwd.googlegroups.com>,
.
.
.
I recommend you consider this possibility: instead of printing
in general, think about whether it's practical to make a print-
ing facility that requires a PostScript printer. That might be
OK with your users, and simplify your work a great deal, as the
experience you describe already suggests.

Stefaan

unread,
Aug 27, 2006, 6:01:06 AM8/27/06
to

If you use the postscript export functionality from the canvas together
with gostscript, you can print your forms easily using following code.
Your form must be created first on a canvas scale 1:1 (path for canvas
is in $WIN(FRM)).
This code is written for Windows environment, but should be easily
modified for other environments, as gostscript is available for multiple
platforms.

Usage :

OpenPrinter
PrintForm (1 or multiple times)
ClosePrinter

sx and sy are shifts to get the form on the right place on paper, this
values are obtained by calibration.
fwdt and fhgt are form width and height.


#
#
proc Print::OpenPrinter {} {

variable WIN
variable FLD
variable CUR

$WIN(FRM) itemconfigure img -state hidden
update

set gspath {C:\\gs\\gs8.51\\bin\\gswin32c.exe}
set opt1 "-q"
if {$FLD(Printer) != "Select from Printer Dialog"} {
set opt2 "-sDEVICE=mswinpr2
-sOutputFile=\"%printer%$FLD(Printer)\""
}\
else {
set opt2 "-sDEVICE=mswinpr2"
}
set opt3 "-dNOPAUSE -dBATCH"
set CUR(gs) [open "|\"$gspath\" $opt1 $opt2 $opt3 -" w]
}

#
#
proc Print::PrintForm {} {

variable WIN
variable FLD
variable CUR
variable Msg ""

GetValues sx sy fwdt fhgt unit rot
if {$rot} {
set sftx [expr {$sx + $fwdt / 2}]
set sfty [expr {$sy + $fhgt / 2}]
}\
else {
set sftx [expr {-1 * $sy + $fwdt / 2}]
set sfty [expr {$sx + $fhgt / 2}]
}

$WIN(FRM) yview moveto 0
$WIN(FRM) xview moveto 0

$WIN(FRM) postscript -channel $CUR(gs) -pagey $sftx$unit \
-pagex $sfty$unit -rotate $rot -width $fwdt$unit \
-height $fhgt$unit -pageheight $fhgt$unit \
-pagewidth $fwdt$unit -x 0 -y 0
}

#
#
proc Print::ClosePrinter {} {

variable WIN
variable CUR
variable Msg ""

catch {close $CUR(gs)} Msg
array unset CUR gs

$WIN(FRM) itemconfigure img -state normal
update
}


Stefaan

Peter Bauer

unread,
Aug 27, 2006, 8:20:22 AM8/27/06
to
>> I'm a beginner in TCL/TK, and I'm looking for an idea how to issue a
>> print reqest with TCL/TK.
>>
>
> Which OS?
>
> Unfortunately, do the differences in how OSes handle print systems there
> is not one easy answer.

Since TCL/TK is portable, I'd like to be able to print on Windows and Unix
and Linux.

Some other responses pointed me to pdf4tcl, which might be a solution, if I
have TCL to open the generated PDF. I'll take a look at that situation.


Peter Bauer

unread,
Aug 27, 2006, 8:21:44 AM8/27/06
to

"Stefaan" <nws3...@skynet.be> schrieb im Newsbeitrag
news:44f16c70$0$31475$ba62...@news.skynet.be...

>> I'm a beginner in TCL/TK, and I'm looking for an idea how to issue a
>> print reqest with TCL/TK.
>>
>

> If you use the postscript export functionality from the canvas together
> with gostscript, you can print your forms easily using following code.
> Your form must be created first on a canvas scale 1:1 (path for canvas is
> in $WIN(FRM)).
> This code is written for Windows environment, but should be easily
> modified for other environments, as gostscript is available for multiple
> platforms.

Thank you. I'll take a look at the code and try it out.

Again, thanks!

Peter


Larry W. Virden

unread,
Aug 29, 2006, 10:01:54 AM8/29/06
to

Peter Bauer wrote:

> I'm a beginner in TCL/TK, and I'm looking for an idea how to issue a print
> reqest with TCL/TK.

The thing is, print request means different things to different people.
Some people want to output lines to a printer. Some people want to
create graphics and output them in some format suitable for printing
(and some printers print postscript while others may not ... or at
least may require the owner to purchase a postscript add-on package).
Windows has an OS level type print capability, with GUI dialogs for
selecting printers, setting options, etc. I don't know what MacOS
provides, but most Unix systems have commands like "lpr" or "lp" which
one invokes via command line and hopes that the system coordinator has
installed drivers to handle the file format in question. Some
developers just generate PostScript and make that a prerequisite to
using their programs.

Tcl itself doesn't have anything specific for printer support. Each OS
has some method of referencing printers (/dev/printer, or printer
names, or some sort of windows printer device, etc.), and if the os
supports it, I suppose, in Tcl, one could open the device and write
what is needed there.

I do know that several Windows Tcl developers have written specialty
extensions for handling printers... I don't know, however, whether any
of these have, as yet, made it into the popular ActiveTcl binary
distribution.

> My job is to write a frontend for a database application, and users need to
> be able to print reports. Can you point me to a direction how I could solve
> this? If possible, the print should be somewhat graphical (invoices, need to
> print some lines).

Starting here is a good begining. However, you probably want to
describe a bit more of what it is you are doing. Are you, for instance,
taking user input, generating a Tk window, then wanting to print that
window? Are you taking user data, then wanting to write directly to the
printer a report, without doing any graphical representation? Each of
these approaches requires different work to get it onto a printer.

Manfred Stelzhammer

unread,
Aug 29, 2006, 1:04:03 PM8/29/06
to
0 new messages