# Re[2]: st: Printing graphs to pdf under program control

 From Ian Watson To Gary Longton Subject Re[2]: st: Printing graphs to pdf under program control Date Fri, 15 Oct 2004 18:25:25 +1000

Dear Gary,

Thanks very much for the suggestion about using Distiller's "watched
folders" to convert Stata graphs into PDF files under Windows. I've
tried a couple of approaches now and might report to the list on my
results.

My initial attempts to simply print graphs to Distiller under program
control (ie. within a do file) came unstuck because there was no way
to pass the filename to Distiller except interactively.

Similarly, I have only had success using export to postscript and the
.ps file in Distiller when I do it interactively. I notice one problem
here is that Distiller can't find the Hevetica fonts which Stata uses,
but it goes ahead and substitutes, so that is not a serious impediment.

Gary's suggestion of using the watched folders option in Distiller
(see below for details) hasn't worked for me because Distiller refuses
to complete the pdf conversion and just complains about the Helvetica
fonts. All my Distiller settings are identical between the manual
/interactive approach and the watched folders approach, so I'm not
sure why this problem occurs.

Having originally posed the problem as one of printing to Distiller, I
have become convinced that the export to eps and then convert to pdf
via the epstopdf program (suggested by Philippe Van Kerm a few days
ago, see details below) is the best solution. While Distiller is a
nice program and gives the user good control over resolution (as high
as 2400 dpi), it has a couple of downsides:

1. (apparently) no program control directly, my original goal
(though I would still like to know if there is a hook somewhere in
Stata for sending a string to an application like Distiller)

2. the watched folders approach (even if I could get it to work)
requires Distiller to monitor the folder all the time (the default
setting is 10 secs, but you would want to set it to 1-2 secs for useful
processing)

In summary, my problem is solved, and I think Philippe's
grexportpdf.ado code (see below) works a treat.

Thanks to both Philippe and Gary for their help.

Ian Watson
acirrt
University of Sydney

Gary Longton wrote:

GL> An approach which uses Distiller, rather than the 3rd party eps converter that
GL> Philippe suggests, involves setting the "watched folders" in Distiller (settings
GL> menu).  \in and \out subdirectories of this directory will be created.   -Graph
GL> export- to the \in subdirectory in ps format, i.e.

GL>     .graph export <watched folder path>\in\<filename>.ps, ps_options

GL> The ps file will be automatically converted to pdf and placed in the \out
GL> subdirectory of your "watched folder".

GL> Included among the -graph export- ps options is the scale (-mag()-) option you
GL> are looking for, along with page size, margin size, orientation, etc.

GL> Though I've often used -graph export- (to ps) and Distiller to generate pdf
GL> files, I have to admit that I've not used the "watched folders" setting in the
GL> past to do this (did not really know it was possible until recently).
GL> Interactive conversion of multiple ps files to pdf is otherwise an easy 3-click
GL> procedure with Distiller when it is set as the default app for opening ps files,
GL> and just a couple of clicks more when not.

GL> - Gary

Philippe Van Kerm wrote a few days ago:

...  under Windows, I've used the command-line converter -epstopdf-
(available in most LaTeX distributions I believe) without any problem. That
is: I export my Stata graph to EPS, call the external command -epstopdf- to
convert it to PDF, and the PDF file can be imported and PDFLaTeX-ed without
a glitch.

This can be done a one-step procedure with the following programme. Use
-grexportpdf using ... - instead of the official -graph export ...-

*! grexportpdf 1.0, Ph.Van Kerm, Aug-2003
* this command exports current graph to PDF (requires epstopdf installed!!)
*  grexportpdf using path/filename
cap pr drop grexportpdf
pr def grexportpdf
version 8
syntax using/
loc using = subinstr("using'",".pdf","",.)
gr export "using'.eps" , replace
!epstopdf "using'.eps"
erase "using'.eps"
end

GL> Ian Watson  originally wrote:
>>
>>   Has anyone had success passing a filename under program control to
>>   Acrobat Distiller on a Windows platform?
>>
>>   I wish to print my graph to a pdf file, but graph export (to pdf) is
>>   not available under Windows. I can of course print to Acrobat
>>   Distiller manually. But what I want to do is automate the procedure
>>   inside a do file.  . . .

>>    . . .  Finally, not all of the print graphic controls from the dialogue box
>>   (Graphic Preferences - Printer) appear to be available in syntax, or
>>   have I overlooked something? In particular, I notice missing are the
>>   color mapping options, and the scaling options.
>>
>>   Any advice on these matters would be greatly appreciated.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/