Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: ps2pdf.ado


From   "Dimitriy V. Masterov" <[email protected]>
To   [email protected]
Subject   st: ps2pdf.ado
Date   Fri, 12 Nov 2004 20:19:25 -0600 (CST)

I got some comments from people about the ps2pdf program, which I've
incorporated. I've also added error messages and made it a bit more
user-friendly. You can download it from
http://lily.src.uchicago.edu/~dvmaster/FILES/Stata/ps2pdf.ado or see the
code below in case our server dies sometime in the future.

DVM


// DESCRIPTION:
// This program "distills" a single PDF file from one or more PS files in
a specified folder on a Windows PC using Adobe Acrobat Distiller.

// DIRECTIONS:
// After you have exported some graphs to PS format, you can either type
(1) ps2pdf or (2) ps2pdf C:/.../Folder/outputfilename.txt, in the command
window or in your do-file. Method (1) will produce a file named
ps2pdf_output.pdf in your working directory if there are any PS files
there. Method (2) will yield outputfilename.pdf, which will contain ALL of
the PS files in C:/.../Folder/. MOST IMPORTANTLY, ALL OF THE PS FILES AS
WELL AS THE TXT FILE CREATED BY THIS PROGRAM WILL BE ERASED AT THE END.
You may need to modify the path for Distiller (acrodist.exe) to suit your
own computer.

// MISC.:
// V1.0 by Dimitriy V. Masterov on 11/10/04, V1.1 on 11/12/04.
// E-mail me with comments, suggestions and questions at dvmaster at
lily.src.uchicago.edu. */


program define ps2pdf
	version 8.2

#delimit;

local arg=trim("`*'");

/* This will kick in if you just type ps2pdf */
if "`arg'" == "" {;
	local arg "`c(pwd)'/ps2pdf_output.txt";
	di as green _newline(1) "Note: Your output file ps2pdf_output.pdf
will be put in `c(pwd)'";
};


/* This ensures that all the slashes in the path are virgules because
Distiller is picky */
tempname star;
local `star'=subinstr("`arg'","\","/",.);

/* This step splits the argument of ps2pdf into a path and an output file
name */
tempname path output;

/* This defines the name of the output file from the argument */
tokenize ``star'', parse(/);
local n=1;
	while "``n''" != "" {;
	local `output'  "``n''";
	local n=`n'+1;
};

/* This ensures that you added outputfilename.txt in the command */
if match("``output''","*.txt") != 1 {;
	di as red _newline(1) "Error: Your forgot to include an
outputfilename.txt at the end of" _newline(1) _column(8) "ps2pdf
``star''.";
};

else {;
		/* n is the length of the path (including each "/") */
		local n=`n'-3;

		/* This puts all the pieces of the path together */
		local i=2;
		local j=`i'-1;
			while `i' <= `n' {;
				local `j' "``j''``i''";
				local `path' "``j''";
			local i=`i'+1;
		};

		/* This checks to see if there are any PS files in the
folder. If they exist, the distillation takes place */
		tempname pslist;
		local `pslist' : dir "``path''\" files "*.ps";

		if  `"``pslist''"' == "" {;
			di as red _newline(1) "Error: No PS files were
found in ``path''.";
		};

		else {;

				/* This step allows for the PathName line
to evaluate correctly */
				tempname input;
				local `input' "``path''/*.ps";

				/* The echo step makes the input file for
Distiller to use */
				!echo
				/PathName (``input'') def
						/RunDir {
								{ /mysave
save def

dup = flush

RunFile

clear cleardictstack

mysave restore
								}
								255 string

filenameforall
						} def
				PathName RunDir > ``path''/``output'';

				/* This step "distills" the input file
						/N opens a new Distiller
window.
						/Q closes it when the
program finishes.
						/V opens the new PDF file.
						See
http://www.adobe.com/support/techdocs/321090.html for more details */
				! "C:\Program Files\Adobe\Acrobat
6.0\Distillr\acrodist.exe" /N /Q /V ``path''/``output'';


				/* This step deletes the Distiller input
file */
				erase ``path''/``output'';

				/* This ensures that all the slashes are
NOT virgules because DOS is picky.
				THIS WILL DELETE ALL OF THE PS FILES THAT
YOU HAVE IN YOUR PATH FOLDER */
				local
`input'=subinstr("``input''","/","\",.);
				!del ``input'';
		};
};

discard;

end;



*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index