Fanning Software Consulting

Creating PDF Files in IDL

QUESTION: I realize I can create PostScript files in IDL and then convert these to PDF files with external software like Adobe Distiller. But I don't like that solution. Isn't there some way to do this directly from within IDL!?

ANSWER: Here is how I created a PDF file directly from IDL on my Windows machine.

(1) Download the free CutePDF Writer software from the fine folks at Globalscape and install it. (Great FTP software, too!)

(2) Type the following commands in IDL:

   IDL> Set_Plot, 'PRINTER'
   IDL> ok = Dialog_Printersetup()

At this point I selected the CutePDF Writer from my list of printers.

   IDL> Plot, findgen(11)
   IDL> Device, /Close

Whala! A PDF document with my graphics was created! Easy, easy, easy!!

Note that if you have Adobe Acrobat, you can also use the Adobe PDF printer that is installed with Acrobat to accomplish the same thing.

Unfortunately, I don't know of any way to select the correct PDF printer programmatically from within IDL. The user is required to select the printer manually from the printer dialog. This make automatic generation of PDF files problematic.

Machine Independent PDF Files in IDL

I have created a new Coyote Graphics program, named cgPS2PDF, that can be used in a machine independent way to create PDF files from PostScript intermediate files. On Windows and UNIX computers, excluding Macintosh computers, the conversion is done with Ghostscript, a free, easily obtained and installed software package. Most UNIX systems come with this already installed. There are 32-bit and 64-bit versions available for both Windows and UNIX users. The Macintosh computer uses the built-in pstopdf program to do the conversion for you. Keywords allow UNIX users to select other conversion programs, such as pstopdf or esptopdf, to perform the conversion.

After installing Ghostscript, creating a PDF file can be as simple as this.

   cgPS_Open, File=''
   cgHistoplot, cgDemoData(7), /Fill
   cgPS2PDF, ''

A file named test.pdf is created in the same directory the PostScript file resides in.

The cgPS2PDF program can be invoked in various ways. For example, it can be invoked directly from cgPS_Close. In the following case, the PostScript file is created, but deleted after the PDF file is made.

   cgPS_Open, File=''
   cgHistoplot, cgDemoData(7), /Fill
   cgPS_Close, /PDF, /Delete_PS

A PDF file can be made in this way directly from a cgWindow. Simply select the PDF File option under the Save As menu option.

   cgHistoplot, cgDemoData(7), /Fill, /Window

A recent update (14 Dec 2011) to the Coyote Graphics programs, now allows PostScript, PDF, and five types of raster file output to be created directly from the Coyote Graphics graphics command. For the histogram plot, for example, you can now just type this.

   cgHistoplot, cgDemoData(7), /Fill, Output='test.pdf'

Such graphics output compares favorably with the output from IDL 8 function graphics commands, although Coyote Graphics output files are generally smaller in size.

[Return to IDL Programming Tips]