[OS X TeX] Re: Turning eps to pdf problems

Gerben Wierda Gerben.Wierda at rna.nl
Mon May 22 21:13:37 CEST 2006


On 22 May 2006, at 02:48, Stephen Moye wrote:

>
> On May 21, 2006, at 8:35 PM, Bill Rowe wrote:
>
>> On 5/21/06 at 8:05 PM, stephenmoye at cox.net (Stephen Moye) wrote:
>>
>>> On May 21, 2006, at 7:54 PM, Ross Moore wrote:
>>
>>>> Can you put it on a web-site, then send the URL ? That's always the
>>>> best, since only people who are interested will download it, at
>>>> their own leisure.
>>
>>> Excellent idea:
>>
>>> http://homepage.mac.com/stephenmoye/FileSharing6.html
>>
>> FWIW, PStill found at http://www.pstill.com/ converts this from  
>> eps to pdf without changing the fonts to bit mapped.
>
> I always forget about pstill, and you're right -- it does work. I  
> was hoping for a command line utility, though.

/* pstill.m, command line interface to Pstill: */

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <stdio.h>
#import <mach/mach.h>
#import <servers/bootstrap.h>
#include <unistd.h>

/* to compile:

cc -Wall   -c -o pstill.o pstill.m
cc -framework AppKit  pstill.o   -o pstill-cli

*/

#define PStillFilterServer  ([NSString \
			      stringWithFormat:@"PStillFilterServer-%@",\
			      [[NSProcessInfo processInfo] hostName]])

@protocol PStillVended

// 0 = succes anything else = failure
// caller's responsibility to make sure outputFile is writeable and not
// existing!
- (int)convertFile:(NSString *)inputFile
     toPDFFile:(NSString *)outputFile deleteInput:(BOOL)deleteInput;

// you can also convert many files to one single PDF with this one:
- (int)convertFiles:(NSArray *)fullPathsToFiles
     toPDFFile:(NSString *)outputFile deleteInput:(BOOL)deleteInput;

// when licensing is done, this will return YES, otherwise NO
- (BOOL)applicationReadyForInput;

// for jobs to show a preview from a thread
- (void) showImageFile:(NSString *)file width:(int)width height:(int) 
height
     isEPS:(BOOL)isEPS rotation:(int)rotation pageNumber:(int) 
pageNumber;

@end

#define USAGE NSLog(@"This Print Filter requires PStill for Mac OS X  
by Stone Design and Frank Siegert. Visit www.stone.com to download  
and full information.")

#define WAKE_UP_WAIT	5

static id<PStillVended> lookupPStillDOServer(void) {
     port_t sendMachPort;
     NSDistantObject *rootProxy = nil;
     id<PStillVended> result;

     // First, try look up PStill;s DO object in the bootstrap server.
     // This is where the app registers it by default.
     if ((BOOTSTRAP_SUCCESS ==
	 bootstrap_look_up(bootstrap_port,
			   (char *)([PStillFilterServer cString]),
			   &sendMachPort)) && (PORT_NULL != sendMachPort)) {
	NSConnection *conn = [NSConnection
			      connectionWithReceivePort: [NSPort port]
			      sendPort:[NSMachPort
					portWithMachPort:sendMachPort]];
	rootProxy = [conn rootProxy];
     }

     // If the previous call failed, the following might succeed if  
the user
     // logged in is running Terminal with the PublicDOServices user  
default
     // set.
     if (!rootProxy) {
	rootProxy = [NSConnection rootProxyForConnectionWithRegisteredName:
		     PStillFilterServer host:@""];
     }

     // We could also try to launch PStill at this point, using
     // the NSWorkspace protocol.

     if (!rootProxy) {
	if (![[NSWorkspace sharedWorkspace] launchApplication:@"PStill"]) {
	    USAGE;
	    return nil;
	}
	sleep(WAKE_UP_WAIT);
	rootProxy = [NSConnection  
rootProxyForConnectionWithRegisteredName:PStillFilterServer host:@""];
     }

     if (!rootProxy) {
	fprintf(stderr,"Can't connect to PStill\n");
	return nil;
     }

     [rootProxy setProtocolForProxy:@protocol(PStillVended)];
     result = (id<PStillVended>)rootProxy;
     return result;
}

BOOL convertFiles(NSArray *inputFiles, NSString *outputFile) {
     id<PStillVended> theProxy = lookupPStillDOServer();
     // if we can't find it, bail:
     if (theProxy != nil) {
	// if she's not launched, we wait until she's licensed or they
	// give up on licensing:
	while (![theProxy applicationReadyForInput]) {
	    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow: 
0.1]];
	}

	if (([inputFiles count]==1 && [theProxy convertFile:[inputFiles  
objectAtIndex:0] toPDFFile:outputFile
	     deleteInput:NO] == 0)) {
	    return YES;
	} else if ([theProxy convertFiles:inputFiles toPDFFile:outputFile
	     deleteInput:NO]) {
	    return YES;
         } else {
	    NSLog(@"Couldn't convert %@",[inputFiles objectAtIndex:0]);
	}
     }
     else {
	NSLog(@"Couldn't connect to PStill");
     }
     return NO;
}

NSString * fullPathForCString(char *cString,char *cwd) {
     if (cString[0] == '/') return [NSString stringWithCString:cString];
     else return [[NSString stringWithCString:cwd] 
stringByAppendingPathComponent:[NSString stringWithCString:cString]];
}

int main( int argc, char *argv[])
{
     NSAutoreleasePool *pool;
     NSString *pdfFile;
     NSMutableArray *files;
     unsigned int i;

     char cwd[2048];

     if (argc != 3) {
	fprintf( stderr, "%s: wrong number of arguments: %d\n",
		 argv[0], argc);
	fprintf( stderr, "USAGE: %s psInputFile pdfOutputFile\n",
		 argv[0]);
	fprintf( stderr, "or to merge many ps's into one pdf:\n %s  
psInputFile0 psInputFile1 ... psInputFileN pdfOutputFile\n",
		 argv[0]);
	exit( 1);
     }

     getwd( cwd);
     pool =[[NSAutoreleasePool alloc] init];
     files = [NSMutableArray array];

     for (i = 1; i < argc - 1; i++) {
         [files addObject:fullPathForCString(argv[i],cwd)];	// could  
be as few as one
     }
     pdfFile = fullPathForCString(argv[argc-1],cwd);

     fprintf( stderr, "pstill: distilling %s to %s\n", [[files  
objectAtIndex:0] cString], [pdfFile cString]);
     fflush( stderr);

     return !convertFiles( files, pdfFile);

     [pool release];
}

------------------------- Info --------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
          & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/




More information about the macostex-archives mailing list