programatically printing to a postscript file

  • Hi everyone,

    I am writing a simple Cocoa program and I need to programatically
    print to a postscript file programatically.

    I used below code to print to a pdf file, but I cannot figure out how to
    save postscript file.

    NSMutableDictionary *pdict = [NSMutableDictionary
    dictionaryWithDictionary:[[NSPrintInfo sharedPrintInfo] dictionary]];
    NSPrinter *printer = [NSPrinter printerWithName:@"myprinter"];
    [pdict setObject:@"/tmp/sampe.pdf" forKey:NSPrintSavePath];
    NSPrintInfo *pinfo = [[NSPrintInfo alloc] initWithDictionary:pdict];
    [pinfo setLeftMargin:0.0];
    [pinfo setRightMargin:0.0];
    [pinfo setTopMargin:0.0];
    [pinfo setBottomMargin:0.0];
    [pinfo setPaperSize:[self bounds].size];
    [pinfo setJobDisposition:NSPrintSaveJob];
    [pinfo setPrinter:printer];
    NSPrintOperation *pop = [NSPrintOperation
    printOperationWithView:self printInfo:pinfo];
    [pop setShowsPrintPanel:NO];
    if (![pop runOperation]) NSLog(@"printing failed");
    [pinfo release];

    Is there anyway to select "Save PDF as Postscript..." programatically?

    Thanks in advance,

    Jaeho,
  • Hi everyone,

    I am writing a simple Cocoa program and I need to programatically
    print to a postscript file programatically.

    I used below code to print to a pdf file, but I cannot figure out how to
    save postscript file.

    NSMutableDictionary *pdict = [NSMutableDictionary
    dictionaryWithDictionary:[[NSPrintInfo sharedPrintInfo] dictionary]];
    NSPrinter *printer = [NSPrinter printerWithName:@"myprinter"];
    [pdict setObject:@"/tmp/sampe.pdf" forKey:NSPrintSavePath];
    NSPrintInfo *pinfo = [[NSPrintInfo alloc] initWithDictionary:pdict];
    [pinfo setLeftMargin:0.0];
    [pinfo setRightMargin:0.0];
    [pinfo setTopMargin:0.0];
    [pinfo setBottomMargin:0.0];
    [pinfo setPaperSize:[self bounds].size];
    [pinfo setJobDisposition:NSPrintSaveJob];
    [pinfo setPrinter:printer];
    NSPrintOperation *pop = [NSPrintOperation
    printOperationWithView:self printInfo:pinfo];
    [pop setShowsPrintPanel:NO];
    if (![pop runOperation]) NSLog(@"printing failed");
    [pinfo release];

    Is there anyway to select "Save PDF as Postscript..." programatically?

    Thanks in advance,

    Jaeho,
  • On Jul 9, 2006, at 10:58 AM, Jae Ho Lee wrote:

    > Hi everyone,
    >
    > I am writing a simple Cocoa program and I need to programatically
    > print to a postscript file programatically.
    >
    > I used below code to print to a pdf file, but I cannot figure out
    > how to
    > save postscript file.
    >
    > NSMutableDictionary *pdict = [NSMutableDictionary
    > dictionaryWithDictionary:[[NSPrintInfo sharedPrintInfo] dictionary]];
    > NSPrinter *printer = [NSPrinter printerWithName:@"myprinter"];
    > [pdict setObject:@"/tmp/sampe.pdf" forKey:NSPrintSavePath];
    > NSPrintInfo *pinfo = [[NSPrintInfo alloc] initWithDictionary:pdict];
    > [pinfo setLeftMargin:0.0];
    > [pinfo setRightMargin:0.0];
    > [pinfo setTopMargin:0.0];
    > [pinfo setBottomMargin:0.0];
    > [pinfo setPaperSize:[self bounds].size];
    > [pinfo setJobDisposition:NSPrintSaveJob];
    > [pinfo setPrinter:printer];
    > NSPrintOperation *pop = [NSPrintOperation
    > printOperationWithView:self printInfo:pinfo];
    > [pop setShowsPrintPanel:NO];
    > if (![pop runOperation]) NSLog(@"printing failed");
    > [pinfo release];
    >
    > Is there anyway to select "Save PDF as Postscript..." programatically?

    I don't think there is. You could call the PDF to PS filter in the
    printing system directly after you generated the PDF. On the command
    line that would look something like this:

    /usr/libexec/cups/filter/cgpdftops someJobID userName 'TheDocTitle' 1
    '' 'myFile.pdf' >'myFile.ps'

    Good luck!

    Gerd