Take the 2-minute tour ×

Brad Miller @ Cocoa Dev Central wrote a tutorial regarding Creating PDFs from Cocoa. I tried to follow the tutorial there, but since its rather old (2003) a lot of code was deprecated. I got it to work after some fiddeling, but when I try to export a PDF, the print-dialog shows, and it does not save the PDF to the file I specified.

NSPrintInfo *printInfo;
NSPrintInfo *sharedInfo;
NSPrintOperation *printOp;
NSMutableDictionary *printInfoDict;
NSMutableDictionary *sharedDict;

sharedInfo = [NSPrintInfo sharedPrintInfo];
sharedDict = [sharedInfo dictionary];
printInfoDict = [NSMutableDictionary dictionaryWithDictionary: sharedDict];

[printInfoDict setObject:NSPrintSaveJob

[printInfoDict setObject:[panel URL] forKey:NSPrintSavePath];

printInfo = [[NSPrintInfo alloc] initWithDictionary:printInfoDict];
[printInfo setHorizontalPagination: NSAutoPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];

printOp = [NSPrintOperation printOperationWithView:textView

[printOp setShowsProgressPanel:NO];
[printOp runOperation];

The complete code for my export PDF implementation is here. The code above is just regarding the export.

Would be very happy if someone could see the what Im doing wrong here...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Actually, I found the answer to my problem myself here when I read through it again. The problem is with the line containing:

[printInfoDict setObject:[panel URL] forKey:NSPrintSavePath];

As you can see, the file URL is picked up there, but it should be a path instead of an URL. So I changed it to this:

[printInfoDict setObject:[[panel URL] path] forKey:NSPrintSavePath];

And wham, it works!

share|improve this answer

Your Answer


