I'm trying to set up a print dialog, so that if the user tries to save to PDF, it gets a reasonable filename.
I currently have:
NSPrintInfo* pi = [NSPrintInfo sharedPrintInfo];
NSMutableDictionary *dict = [pi dictionary];
[dict setObject: name forKey: NSPrintSavePath];
[dict setObject: name forKey: @"NSPrintSavePath"];
NSPrintOperation *op = [pdfDoc getPrintOperationForPrintInfo:pi
autoRotate:YES];
[op runOperation];
the NSPrintSave field in the dictionary IS correct, but the textbox keeps coming up with ".pdf.pdf"
any thoughts on where that's coming from?
Added info:
When I print out my NSPrintInfo object, I get:
print info {
NSBottomMargin = 90;
NSCopies = 1;
NSDetailedErrorReporting = 0;
NSFaxNumber = "";
NSFirstPage = 1;
NSHorizonalPagination = 2;
NSHorizontallyCentered = 1;
NSJobDisposition = NSPrintSpoolJob;
NSJobSavingFileNameExtensionHidden = 0;
NSJobSavingURL = bob -- /;
NSLastPage = 2147开发者_如何学编程483647;
NSLeftMargin = 72;
NSMustCollate = 1;
NSOrientation = 0;
NSPagesAcross = 1;
NSPagesDown = 1;
NSPaperName = "na-letter";
NSPaperSize = NSSize: {612, 792};
NSPrintAllPages = 1;
NSPrintProtected = 0;
NSPrintSavePath = bob;
NSPrintTime = 0001-12-31 19:00:00 -0500;
NSPrinter = {
"Device Description" = {
NSDeviceIsPrinter = YES;
};
"Language Level" = 2;
Name = "Xerox WorkCentre PE120 Series (XRX0000aa9915f0)";
Type = "Generic PostScript Printer";
};
NSPrinterName = "Xerox WorkCentre PE120 Series (XRX0000aa9915f0)";
NSRightMargin = 72;
NSSavePath = bob;
NSScalingFactor = 1;
NSTopMargin = 90;
NSVerticalPagination = 0;
NSVerticallyCentered = 1;
}
I woud think that this would mean that the default filename to print to would be "bob", or "bob.pdf" but it's still ".pdf.pdf"...
The answer, it would appear, is to completely ignore the NSPrintInfo, and look at the NSPrintOperation. evidently, NSPrintOperation has a setJobTitle method, which just does The Right Thing (tm).
Now, why none of my google searching found this (all of it lead to the stuff I tried above) I really don't know...
精彩评论