comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Window Contents Directly to Printer
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Window Contents Directly to Printer [message #11247] Wed, 18 March 1998 00:00 Go to next message
davidf is currently offline  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/
Re: Window Contents Directly to Printer [message #11357 is a reply to message #11247] Fri, 20 March 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Sorry, I wanted to make one more point.

Samuel Haimov writes:

> Long time ago I tried to use PRINTER device and I found that
> the quality of the print is not very good.

Remember that what the Print_It program does is send a
*screen dump* of the graphics window to the printer. That
is, by definition, low resolution (i.e, 72 pixels per inch
as compared to 600 pixels per inch for most PostScript printers).

If you want high quality PostScript output, look at a program
like XWindow on my web page, a "smart" graphics window
that can send its contents to a PostScript file (or to the
PRINTER if you like, with 30 seconds of modification) in
the very highest resolution mode.

My book describes in quite a bit of detail exactly how
this is done.

Cheers,

David
-----------------------------------------------------------
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/
Re: Window Contents Directly to Printer [message #11358 is a reply to message #11247] Fri, 20 March 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
John Smith aka Samual Haimov (jsmith@company.com) writes:

> Long time ago I tried to use PRINTER device and I found that
> the quality of the print is not very good.
>
> I tried it again now using print_it and as before it came out
> with poorly printed labels, etc.
>
> Am I not doing something right or as I suspected before this
> is what you get when the video is used ?
>
> The reason I have some doubts about doing something wrong is that
> instead of printing directly to the printer I get an encapsulated
> postscript file xprinter.eps

Uh, this wasn't the BEST program I ever wrote, but I'm
pretty darn sure it doesn't produce encapsulated PostScript
output. :-)

Try renaming the file to print_it_darn_it.pro. Compile the
file like this:

IDL> .Compile print_it_darn_it

Then try to run the Print_It program.

IDL> Window, XSize=300, YSize=300
IDL> TV, Dist(300)
IDL> Print_It, 0

Now you should be running the write Print_It program. :-)

I think you were finding the wrong Print_It program. To
see which program you have, type this:

Help, /Source

It will tell you what directories your compiled procedures
and functions were found in.

Cheers,

David
-----------------------------------------------------------
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/
Re: Window Contents Directly to Printer [message #11359 is a reply to message #11247] Fri, 20 March 1998 00:00 Go to previous message
John Smith is currently offline  John Smith
Messages: 4
Registered: March 1998
Junior Member
Kirt Schaper wrote:
>
> David Fanning wrote:
>>
>> Hi Folks,
>>
>> If anyone is following along or thinks this program is the
>> least bit useful, here is the final PRINT_IT program that
>> Armand and I have come up with. I got some help from the
>> usual anonymous lurkers, as well. :-)
>
> Just to ensure that this horse is totally beaten into the ground,

.... more good stuff deleted

Long time ago I tried to use PRINTER device and I found that
the quality of the print is not very good.

I tried it again now using print_it and as before it came out
with poorly printed labels, etc.

Am I not doing something right or as I suspected before this
is what you get when the video is used ?

The reason I have some doubts about doing something wrong is that
instead of printing directly to the printer I get an encapsulated
postscript file xprinter.eps

Samuel Haimov
haimov@uwyo.edu (ignore the header name and email)
Re: Window Contents Directly to Printer [message #11360 is a reply to message #11247] Fri, 20 March 1998 00:00 Go to previous message
Kelly Dean is currently offline  Kelly Dean
Messages: 92
Registered: March 1997
Member
Great work guys -- I like this. It is set up as a PrintScreen macro on
my version of IDL 5.0.

However, I just wanted to point out a typo:

window,/free,/PIXMAP,XSIZE=!d.x_size,YSIZE=!d.ysize

should be ( y_size ):

window,/free,/PIXMAP,XSIZE=!d.x_size,YSIZE=!d.y_size ; create a temp

Kelly
Re: Window Contents Directly to Printer [message #11379 is a reply to message #11247] Thu, 19 March 1998 00:00 Go to previous message
Kirt Schaper is currently offline  Kirt Schaper
Messages: 6
Registered: February 1997
Junior Member
David Fanning wrote:
>
> Hi Folks,
>
> If anyone is following along or thinks this program is the
> least bit useful, here is the final PRINT_IT program that
> Armand and I have come up with. I got some help from the
> usual anonymous lurkers, as well. :-)

Just to ensure that this horse is totally beaten into the ground,
I think you should change the following lines to avoid the problem
of offscreen or obscured X-windows:

> ; Make the window current. Get contents.
>
> WSet, wid
> contents = TVRD()

If you the following code snippet, you won't get garbage:

; Make the window current. Get contents.
window,/free,/PIXMAP,XSIZE=!d.x_size,YSIZE=!d.ysize ; create a temp
pixmap window
device,copy=[0,0,!d.x_size,!d.y_size,0,0,wid] ; transfer wid
contents
contents = tvrd(0,0,!d.x_size,!d.y_size) ; grab pixmap
contents -- no offscreen problem
; just for us old WAVE programmers, use ALL the tvrd parameters :-{
wdelete, !d.window ; delete the temp
pixmap window
wset, wid ; make the window
current


--
-------------------------------------------------------
Stop explaining, it hurts too much!
-------------------------------------------------------
Kirt Schaper | Bell: (612) 725-2000 x4791
PET Center (11P) | net: kirt@pet.med.va.gov
VA Medical Center | FAX: (612) 725-2068
MPLS, MN 55417 | URL: http://pet.med.va.gov:8080
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Reading string array
Next Topic: call_external question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:26:20 PDT 2025

Total time taken to generate the page: 0.88128 seconds