Setting the file name in NSPrintInfo

I am trying to set up a print dialog, so if the user tries to save to PDF, he will get a reasonable file name.

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 text field continues to ".pdf.pdf"

any thoughts on where this comes from?

Information added:

When I print 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 = 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;
}

I think this will mean that the default print file name will be "bob" or "bob.pdf", but it is still ".pdf.pdf" ...

+3
source share
1 answer

, , , NSPrintInfo NSPrintOperation. , NSPrintOperation setJobTitle, The Right Thing (tm).

, Google ( , ), ...

+6

Source: https://habr.com/ru/post/1740046/


All Articles