Window Contents Directly to Printer [message #11247] |
Wed, 18 March 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Hi Folks,
I've had a number of you ask how to send the contents of
a graphics window directly to the printer in IDL 5.0 like
you used to be able to do in IDL 4.0.
Thanks to some hints from the RSI Tip of the Week, I've
figured out how to do this. (Their tip shows you how to
create a macro for your IDLDE environment. It's a good
tip, except that the program has several lines of unused
code in it, which always makes me nervous.) Here is a very
simple program named Print_It. You simply give it the
window index number of the window you want to print and
it sends the window contents directly to the PRINTER.
Window, 5, XSize=200, YSize=300
TV, Dist(200, 300)
Print_It, 5
If you don't give it a parameter, it uses the current
window by default.
I leave it as an exercise for the reader to figure out
how to print in landscape mode. And if someone can figure
out how to center the window contents on the page, I'll
send them my favorite Barry Lopez book, *Desert Notes/
River Notes*. :-)
Cheers,
David
**********************************************************
PRO Print_It, wid
; This program sends the contents of the specified
; window to the default printer. The current window
; is used if a window index number is not provided.
IF N_Params() EQ 0 THEN wid = !D.Window
; Make the window current. Get contents.
WSet, wid
contents = TVRD()
; Get the sizes of the window.
xsize = !D.X_Size
ysize = !D.Y_Size
; Get the sizes of the PRINTER device.
thisDevice = !D.Name
Set_Plot, 'PRINTER'
Device, Scale_Factor=1
pxsize = !D.X_Size
pysize = !D.Y_Size
; Calculate a scale factor for the printer.
scalefactor = (Float(xsize) / pxsize) > (Float(ysize) / pysize)
Device, Scale_Factor=(1.0 / scalefactor)
; Print it.
TV, contents
Device, /Close_Document
; Clean up.
Set_Plot, thisDevice
END
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|