Re: PDF graphics conversion

"Adam R. Maxwell" <[email protected]> Thu, 27 Sep 2007 17:27:56 -0700
Newsgroups gmane.comp.tex.latex.latex2rtf.devel
Message-ID <[email protected]>
 
On Thursday, September 27, 2007, at 03:34PM, "Adam R. Maxwell" <[email protected]> wrote:
>On OS X, using sips might be interesting, since it generally has pretty good PDF support, and wouldn't require any 3rd party software (gs, ImageMagick).  I might mess with that in my Copious Free Time.

Since I created a PDF graphic today that crashes gs, I had to try this.  In case someone else is interested in the hack, here it is for PDF.

Background:  I use pdflatex exclusively, and I have some valid PDF files that cause GhostScript to barf when converting to png.  On others, gs gets the crop box wrong in comparison with Adobe and Apple's PDF.  However, OS X 10.3 and later have a command-line tool called sips that processes images, and conveniently accepts PDF as input.  With this change and the scaling fixes in svn, I finally don't have to tweak graphics at all in the RTF file, except for the subfigure environment.

static char *SysGraphicsCommand(char *in, char *out, int specify_density_and_crop)
{
    char cmd[512];
	char format[]  = "convert -crop 0x0 -units PixelsPerInch -density %d \"%s\" \"%s\"";
	char format2[] = "convert \"%s\" \"%s\"";
	
	if (specify_density_and_crop == TRUE)
    	snprintf(cmd, 511, format, g_dots_per_inch, in, out);
    else
    	snprintf(cmd, 511, format2, g_dots_per_inch, in, out);
	
#ifdef UNIX
	/* convert works nicely, except for some pdfs, so use gs directly for those */
	if ((strstr(in, ".pdf") != NULL) || (strstr(in, ".PDF") != NULL)) {
#ifdef __APPLE__
        /* if Quartz is available, it does a better job than ghostscript in most cases */
        char form[] = "/usr/bin/sips -s format png -s dpiHeight %d -s dpiWidth %d --out \"%s\" \"%s\"";
    	snprintf(cmd, 511, form, g_dots_per_inch, g_dots_per_inch, out, in);
#else
		char form[] = "gs -q -dNOPAUSE -dSAFER -dBATCH -sDEVICE=pngalpha -r%d -sOutputFile=\"%s\" \"%s\"";
    	snprintf(cmd, 511, form, g_dots_per_inch, out, in);
#endif
    }
#endif

	return strdup(cmd);
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/