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
forKey:NSPrintJobDisposition];
[printInfoDict setObject:[panel URL] forKey:NSPrintSavePath];
printInfo = [[NSPrintInfo alloc] initWithDictionary:printInfoDict];
[printInfo setHorizontalPagination: NSAutoPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];
printOp = [NSPrintOperation printOperationWithView:textView
printInfo:printInfo];
[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…
Actually, I found the answer to my problem myself here when I read through it again. The problem is with the line containing:
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:
And wham, it works!