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

Printing in Tcl

169 views
Skip to first unread message

TCLFriend

unread,
Sep 19, 2009, 9:37:28 AM9/19/09
to
Hello to all,

I would like to create a small gui application with ability to print
plain-text reports. It will be used mainly on Linux, but it is
possible that also on MS Windows. The question is - how can I print
something (text, not graphics) from Tcl? Couldn't find any useful
information, is it really not supported?

Regards!

Sven Muehlensted

unread,
Sep 19, 2009, 12:36:59 PM9/19/09
to
TCLFriend wrote:

One of the not Windows compatible and very hakish methods I choose some
years ago was to write html file, convert it with html2ps and feed the
postscript file directly to lp.
At least Debian also ships a 'a2ps' converter that should be able to
convert plaintext directly to postscript.

Ugly but works.

ZB

unread,
Sep 19, 2009, 2:56:58 PM9/19/09
to
Dnia 19.09.2009 TCLFriend <tclf...@googlemail.com> napisaďż˝/a:

> The question is - how can I print something (text, not graphics) from Tcl?
> Couldn't find any useful information, is it really not supported?

There are some possible ways:

http://wiki.tcl.tk/_/search?S=print&_charset_=utf-8

#v+
2009-07-22 11:40:17 . . . Printing under Windows
2009-06-05 01:08:58 . . . Tcl/Tk Printing Support
2009-05-22 18:38:53 . . . pdict: Pretty print a dict
2009-04-08 11:02:13 . . . printing
2009-02-27 15:47:45 . . . Printing under MacOSX
2008-12-27 00:47:09 . . . quoted-printable
2008-11-12 18:18:31 . . . Brace-level pretty printer
2008-01-07 01:28:34 . . . Print Area Selector
2007-11-13 19:51:36 . . . Printing text files under Windows
2007-05-20 21:54:21 . . . Printing a canvas under Windows
2007-01-26 20:43:54 . . . Printing DYMO Labels with Tcl and tcom
2007-01-09 16:10:12 . . . XML pretty-printing
2006-11-01 13:40:42 . . . Printing a text file to a lpr printer
2006-10-30 22:43:22 . . . Category Printing
2006-10-30 19:49:51 . . . Printing a canvas using GhostScript
2006-05-01 14:17:48 . . . Uploading Type1 fonts to a network printer
2005-10-25 09:38:36 . . . BLT - graph - printing postscript
2005-07-15 12:24:42 . . . email pretty printer
2005-05-20 10:56:37 . . . Printing proc sequence
2004-01-16 18:22:32 . . . BLT - graph - printing from Windows
#v-
--
Zbigniew

Larry W. Virden

unread,
Sep 21, 2009, 7:47:29 AM9/21/09
to


To print, you could:

open a pipe to a command line print command like lpr or lp, and write
the text to the pipeline

open a port to which a printer is connected and write to the printer

use a PDF creation extension, write your report out as a PDF, then
invoke the command appropriate on the platform for printing PDFs

open a text file and write the report out to the file, close the file,
then invoke the command line appropriate on the platform for printing
plain text files

open a file, write out the report as html, then invoke a web browser
with the flags for it to display the html file and to print it

make use of one of the frameworks which allow you to send the report
to a printing component available elsewhere on the machine. There used
to be a framework called ToolTalk for this sort of thing, but I think
that's been long gone and I think something liek CORBA or other
frameworks are now used.

Perhaps others can add to this list.

As you can see, the topic of printing, as popular as it is, is rather
complex because printing means so many different things to people.

TCLFriend

unread,
Sep 22, 2009, 2:54:59 AM9/22/09
to
Thanks for answers so far. Maybe I wasn't specific enough, I must
admit. I know I can do some tricks like write to file, then send it
somehow to the printer. What I was hoping is standarized Tcl package
offering Tcl commands for printig purposes, ideally cross-platform. It
would be great for example to be able to show to the user of any
platform standard printing dialog by invoking single command from the
script.

Robert Heller

unread,
Sep 22, 2009, 8:52:40 AM9/22/09
to

There isn't such a package, unfortunately. Linux, UNIX, and MacOSX ALL
have lp/lpr and lpstat available -- it is trivial to use these programs
to implement a dialog box to select a printer (lpstat will give you a
list of possible printers, their status, and which one is the default)
and to implement sending a Postscript file to the print queue (ie: $canvas
postscript -file "|lpr -P..." ...). MS-Windows is the 'odd ball' here,
with its strange / wonderful printer interface logic. It would be
seriously non-trivial to write an extension for this. Either a large
chunk of Ghostscript would have to be incorporated into this extension
(eg the Postscript => MS-Windows GDI code) OR the canvas widget would
have to be rewritten to implement a 'gdi' command to call the GDI API to
'draw' every item (parallel code to the existing X11 and Postscript
code).

It is far easier to punt. I'm using the pdf4tcl package to generate a
PDF file for one application. The end user is on his/her own to
actually get it on paper. Another app creates a LaTeX file and runs
pdflatex to make a PDF file. Again the user is on his/her own getting
this on paper. Presumably they can download either the MS-Windows port
of Ghostview/Ghostscript or Adobe's reader. There might be some other
free PDF readers (has xpdf been ported to MS-Windows?).

>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Download the Model Railroad System
http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows
hel...@deepsoft.com -- http://www.deepsoft.com/ModelRailroadSystem/

Jeff Godfrey

unread,
Sep 22, 2009, 9:33:27 AM9/22/09
to
Robert Heller wrote:
> At Mon, 21 Sep 2009 23:54:59 -0700 (PDT) TCLFriend <tclf...@googlemail.com> wrote:
>
>> Thanks for answers so far. Maybe I wasn't specific enough, I must
>> admit. I know I can do some tricks like write to file, then send it
>> somehow to the printer. What I was hoping is standarized Tcl package
>> offering Tcl commands for printig purposes, ideally cross-platform. It
>> would be great for example to be able to show to the user of any
>> platform standard printing dialog by invoking single command from the
>> script.
>
> [... snip ...]

> There might be some other
> free PDF readers (has xpdf been ported to MS-Windows?).

FYI, there a number of free PDF readers available for Windows. Among
them...

- Foxit Reader
- PDF-XChange Viewer
- Cool PDF Reader
- Perfect PDF Reader
- Sumatra PDF Viewer

I have some experience with the first two - both of which are nice.

Jeff

0 new messages