Version 28 of printing

Updated 2006-12-30 16:33:29

Use this page to accumulate pointers to various issues tcl has with printing:


Various Printing Question:

How do I print (output a representation of the contents onto a physical sheet of paper) the contents of a text widget that contains various unicode, mixed fonts, etc. ?

How do I print a text widget with embedded images?


Also, see LV's pithy introduction to the complexity of "printing" [L1 ]. link seems broken 15/5/2005

In summary: printing means many things - to some, it means generating a report, like perl's format type command . To others, it means the equivalent of a screen shot of a particular window. To others, it means produce on paper the equivalent of what is on the screen, only scaled to the size on the paper. Or even to write, directly to a printer, the reports. And there may be other interpretations as well.

Different printers can expect data to be in ASCII, PostScript, as well as a variety of custom (and sometimes proprietary) languages.


Windows printer information with no particular connection to Tcl;

    package require registry
    registry keys HKEY_CURRENT_USER\\Printers\\Connections

or

    package require printer
    printer list

"printer" here is Michael I. Schwartz's.


[Discuss use of Xbit to help with printing. Example: the following script will create a Tk photo from a GUI window:

    # create ram image from a GUI window
    rimage window ramimg [rimage window $guiPath frame]

    # create a gimg image from a ram image
    set img [image create gimg -file ramimg]

    # create a Tk Photo named gui.photo
    $img dump gui.photo TKPHOTO 8 1

    # create a canvas image item with the gui.photo and print it

.....]


RS (ab)uses IE as printer driver for multilingual documents by generating a temporary HTML file (see taiku goes multilingual).


KBK's quick-and-dirty Unix-side Tcl-ignorant xwd-enabled screen-dump-to-printer:

    exec xwd -id [winfo id .] | xwdtopnm | ppmtops | lpr

During summer 2002, KBK says on comp.lang.tcl:

I'd love to have native printing on Windows, and would even devote a fair amount of time to it. The difficulty, though, is in coming up with a specification of just what "native printing" is - one that meets the requirements of a fair number of applications.

Generally speaking, page layout is vastly different from screen layout, so what's desired is NOT simply a "print screen" function. Printing a canvas to PostScript comes close for drawing applications, but is totally wrong for a text editor, and a "print" function for the text widget is out of reach unless we can define the pagination mechanism.

It's a hard problem to get started on. The mechanics aren't horribly difficult -- in fact, the hard part from the mechanical standpoint would be a backport of the functionality to Unix. Instead, the really thorny issue is defining what's wanted.


LV It seems like a way to begin would be to brainstorm on the requirements and come to some agreement on the interfaces needed, then take on some portion of functionality that is desired, implementing it, then moving on to the next piece.

As mentioned above, printing means many different things to different people. What if we started with a list of what functionality is needed, along with what techniques exist now for providing that functionality?

Types of printing that a Tcl or Tk developer has identified as a need.

  1. output to a printer simple ASCII text
  2. output to a printer simple ASCII text formatted into one of various report formats
  3. output to a printer text in various fonts and colors as displayed in a tk widget
  4. output to a printer a scaled representation of one or more toplevel windows

There are currently several techniques for accomplishing printing supported by Tcl/Tk.

  1. tcl has the ability to open a device and write plain ASCII characters to it. This provides the crude ability for a text editor to get a file's contents printed. KPV under Windows see Printing text files under Windows
  2. TclVSrpt provides some report creation support
  3. I don't know of anything that provides cross-platform support for printing text in appropriate fonts and colors as displayed in a tk widget.
  4. tk's canvas has the ability to generate a PostScript file that reflects an image of some portion of the canvas's contents. [What are the limitations of the canvas postscript generation?]

In addition, tkprint has the ability on windows to perform some degree of printing.

Now, as people read over this, perhaps they will add the names of other extensions which provide some degree of print support.


Use this to access a Windows way to have a printer properties dialog come up:

 RUNDLL32 PRINTUI.DLL,PrintUIEntry /p /n\\machine\printer

Yet Another Hack To Print Under Windows:

 RUNDLL32.EXE MSHTML.DLL,PrintHTML "C:\Path\To\Somefile.html"

The above will open the Printer selection dialog allowing you to choose where to print. More information available here: [L2 ]


On Unix, one can invoke

 exec lpr filename

or

 exec lp filename

to request a file be printed on the local printer. If the system is configured properly, then the file can be of various formats, and the proper conversions will take place.


SYStems Many people seems to want a database, and few forms to fill the database, Tcl/Tk + Sqlite, fill this need perfectly, but there is also the need to create and print reports/complex queries. So what do you use, preferably a portable solution, the thing, I completely don't understand printing. To display something on screen you use Tk or puts (i.e print txt to a file and view the file), now to send something to a printer? I think puts will still work, since at least on linux, all harder interfaces are files, so there should be a file somewhere. But what about more sophicticated output, tk equivilant of printers? How does printing really works? Not that I know how monitor display really works, but we got Tk so I don't have to worry.

escargo 16 May 2005 - It may be that we need to use pdf4tcl or Trampoline! to generate PDF files rather than driving a printer directly. I know I have been wondering about simple data base input (using some kind of forms) and data base publishing. I just had a disk upgrade that made me lose my Microsoft Windows applications, which meant that I could not access my MS Access data base any more. That made me feel really vunerable. In looking at how to be independent of Microsoft, the issue of how to print my reports comes to the forefront. This is an issue I would love to solve within Tcl.

If PDF can't solve the problem, then perhaps generating HTML might, although that is also limited.


Note that the BI distribution for Mac OS X includes the MacCarbonPrint package.


Category Concept | Category Printing