Fanning Software Consulting

Creating Object Graphic PostScript Output

QUESTION: Can you tell me how to get PostScript output from my object graphics program?

ANSWER: About the only way to get straight PostScript output from object graphics (not encapsulated PostScript output) is to select the Print to File option from the Printer Dialog that appears when you use the Dialog_PrinterSetup command.

   IDL> p = Obj_New('IDLgrPRINTER')
   IDL> ok = Dialog_PrinterSetup(p)

Here is what the dialog looks like on a Windows machine with a PostScript printer selected. Notice the Print to File item is selected.

Printer Dialog allows PostScript file selection.

Now any graphics output drawn to the PRINTER will be written to a PostScript file. This file can be sent directly to a PostScript printer for printing. Be sure to call the NewDocument method to close the file and insert the PostScript "showpage" command into the file. This is what will allow you to print the file directly.

   IDL> p->Draw, theView
   IDL> p->NewDocument

Encapsulated PostScript Output

To create encapsulated PostScript output (the kind that can be inserted into a Microsoft Word document, for example), you must use the Clipboard object. Configure the Clipboard object for the size and resolution you would like in your final output. Resolution is expressed in centimeters per pixel. Dimensions are expressed in the usual units given by the Units keyword. For example, to create a 4 inch by 3 inch graphic, with a resolution of 600 by 600 pixels per inch for output on a normal laser PostScript printer, you might set the Clipboard up like this:

   clipboard = Obj_New("IDLgrClipboard", Dimensions=[4,3], Units=1, $
      Resolution=[2.54/600., 2.54/600.])

To create encapsulated PostScript file, draw the object hierarchy with the PostScript and Filename keywords set, like this:

   clipboard->Draw, theView, Filename='myfile.eps', /PostScript

Note that the output to the file is of a complete PostScript bitmap of the scene to be rendered. This can result in a large file and take a number of seconds to complete. If the graphics scene you are rendering is not too complicated (e.g., it doesn't contain filled polygons, etc.), then you might be better off rendering the scene in vector format. Set the Vector keyword to do so.

   clipboard->Draw, theView, Filename='myfile.eps', /PostScript, /Vector

Be sure to preview your vector PostScript output to be sure it has rendered completely. (Do your preview by printing the PostScript output. Viewing it in Ghostview, for example, is not adequate, since what you see is the screen rendition of the EPS file, not the PostScript rendition. To print this file, you will have to include it in another PostScipt program. For example, you might include it in a Microsoft Word document.)

To preserve the aspect ratio of a object graphics window, you might have to obtain the size of the window first. Here is a section of IDL code taken from my cgSurface program in which I am sending the contents of the window to an Encapsulated PostScript file. The object graphics hierarchy is located in info.thisView and the object window is located in info.thisWindow.

   filename = Dialog_Pickfile(/Write, File='cgsurface.eps')
   IF filename NE '' THEN BEGIN
      resolution = [2.54/600, 2.54/600]
      viewDimensions = 600/72.
      info.thisWindow->GetProperty, Dimensions=windowDimensions, Units=viewUnits
      clipboard = Obj_New('IDLgrClipboard', Dimensions=windowDimensions*viewDimensions, $
         Resolution=resolution, Unit=viewUnits)
      clipboard -> Draw, info.thisView, Filename=filename, /Postscript, /Vector
      Obj_Destroy, clipboard

Web Coyote's Guide to IDL Programming