Version 2 of BLT - graph - printing postscript

Updated 2003-10-08 22:29:06

Printing postscript from the BLT graph widget is pretty easy, much like you can print from canvas widgets. The postscript options are described pretty well in the HTML documentation.

  .g postscript configure -landscape yes -maxpect yes
  .g postscript output

There's another approach you can try. There's an "eps" canvas item in BLT. An "eps" item displays a Tk image that represents some encapsulated PostScript code. You can arbitrarily resize and position the eps item on the canvas. The image is also resized and repositioned.

    canvas .c -width 6.75i -height 5.25i -bg white
    pack .c

    .c create eps 10 620 -file -width 470 -height 400 -anchor sw
    .c create eps 500 10 -file -width 300 -height 300 -anchor nw
    .c create eps 500 320 -file -width 300 -height 300 

    .c create text 20 200 \
        -text "This is a text item" \
        -fill black \
        -anchor w \
        -font { Helvetica 24 bold }
    .c create rectangle 10 10 50 50 -fill blue -outline white
    .c create rectangle 50 50 150 150 -fill green -outline red

But when you print the canvas (i.e. generate PostScript), instead of the image, the encapsulated PostScript is used. The embedded EPS is scaled and translated accordingly. And since the PostScript is transformed, the resolution is much better (device independent). You can still use other canvas item for annotations, company logos, etc. In short, your canvas code is your page description. It's easy to tile graphs and mark them up.

There are different, less well documented approaches to printing under Windows at BLT - graph - printing from Windows But you can also print Postscript from Windows.

To get a list of available printers, you can use the "names" operation.

    # Get a list of printer names
    set printerList [printer names]

    # Pick the first printer
    set printerName [linex $printerList 0]

You open a printer using the "open" operation.

    # Open the printer
    set pid [printer open $printerName]

It returns a printer ID that represents the open printer. It's used with other printer commands. For example to send the graph's PostScript output to a PS printer you can do the following.

    graph .g

    # Save the graph's PostScript in a variable
    set output [.g postscript output]

    # Open a printer and write the output to it
    set pid [printer open $printerName]
    printer write $pid $output
    printer close $pid

The raw PostScript is sent to printer using the "write" operation. The printer is then closed using the "close" operation.

You can access and change printer settings with the "getattr" and "setattr" operations. The "getattr" operation collects the current attributes of the printer. It fill the array variable (given as the last argument) with different values representing the printer state. You can then change the printer settings with the "setattr" operation.

    # Get the printer's current settings
    printer getattr $pid info

    puts "Orientation is $info(Orientation)"
    puts "Paper size is $info(PaperSize)"

    set info(PaperSize) Letter
    set info(Orientation) Landscape
    printer setattr $pid info

To find out the values of valid settings, you can use the "enum" operation. You can query settings for "paper", "quality", "bin", "orientation", "color", "duplex", or "ttoption".

    puts "valid Orientation settings are [printer enum orientation]"

Category BLT