Creating PDF Files with Coyote Graphics
QUESTION: I would like to be able to create PDF files directly from graphical commands. Is this possible using your Coyote Graphics routines?
ANSWER: Yes, of course. All Coyote Graphics display routines now support direct output to PostScript, PDF, or any of five different raster output formats. Simply use the Output keyword on any standard Coyote Graphics routine to select the desired output file type. For example, to save a filled contour plot as a PDF file, you need only do something like this.
cgLoadCT, 33, NColors=8, Bottom=1 data = cgDemoData(2) cgContour, data, Levels=cgConLevels(data, NLEVELS=8), $ C_Colors=Indgen(8)+1, /Fill, /Outline, $ Output='cgfilledcontour.pdf'
A PDF file is immediately created from a PostScript intermediate file, then the PostScript file is deleted. The result can be displayed in any appropriate PDF viewing application.
This Coyote Graphics functionality relies on the Coyote Graphics program cgPS2PDF, which 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 is as simple as executing a Coyote Graphics display command.
cgHistoplot, cgDemoData(7), /Fill, Output='cghistoplot.pdf'
Saving graphical output to a PDF file can also be done from within cgWindow. So, for example, if you wanted to output the contour plot described above to a PDF file, but you also wanted to include a color bar with the plot, you might do it either programmatically, like this, or by selecting the PDF File option from the Save As pull-done menu on the graphics window.
cgLoadCT, 33, NColors=8, Bottom=1 data = cgDemoData(2) levels = cgConLevels(data, NLEVELS=8) cgContour, data, Levels=levels, $ C_Colors=Indgen(8)+1, /Fill, /Outline, $ Position=[0.1, 0.1, 0.9, 0.825], /Window cgColorbar, NColors=7, Bottom=1, OOB_High=8B, $ /Discrete, Range=[Min(levels), Max(levels)], /AddCmd cgControl, Output='filledplot.pdf'
The result can be displayed in any appropriate PDF viewing application.
Version of IDL used to prepare this article: IDL 8.1.