我正在尝试设置打印对话框,这样如果用户尝试保存为PDF,则会获得合理的文件名。
我目前有:
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];
字典中的NSPrintSave字段是正确的,但文本框一直在提出“.pdf.pdf”
关于它来自哪里的任何想法?
添加信息:
当我打印出我的NSPrintInfo对象时,我得到:
print info {
NSBottomMargin = 90;
NSCopies = 1;
NSDetailedErrorReporting = 0;
NSFaxNumber = "";
NSFirstPage = 1;
NSHorizonalPagination = 2;
NSHorizontallyCentered = 1;
NSJobDisposition = NSPrintSpoolJob;
NSJobSavingFileNameExtensionHidden = 0;
NSJobSavingURL = bob -- /;
NSLastPage = 2147483647;
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;
}
我认为这意味着要打印的默认文件名是“bob”或“bob.pdf”,但它仍然是“.pdf.pdf”......
答案 0 :(得分:6)
看来,答案是完全忽略NSPrintInfo,并查看NSPrintOperation。显然,NSPrintOperation有一个setJobTitle方法,它只做了正确的事情(tm)。
现在,为什么我的谷歌搜索都没有找到这个(所有这些都导致了我上面尝试过的东西)我真的不知道......