Brad Miller @ Cocoa Dev Central写了一篇关于从可可中创建PDF的教程。我试着在那里学习教程,但由于它相当旧(2003),很多代码都被弃用了。我让它在一些抖动后工作,但当我尝试导出PDF时,打印对话框显示,它不保存PDF到我指定的文件。
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];我的export PDF实现的完整代码是here。上面的代码只是关于导出的。
如果有人能看到我在这里做错了什么,我会非常高兴的。
发布于 2011-10-29 17:00:08
实际上,当我再次通读时,我自己在这里找到了问题的答案。问题出在包含以下内容的行中:
[printInfoDict setObject:[panel URL] forKey:NSPrintSavePath];如您所见,文件URL在那里被提取,但它应该是一个路径,而不是一个URL。所以我把它改成这样:
[printInfoDict setObject:[[panel URL] path] forKey:NSPrintSavePath];哇,它起作用了!
https://stackoverflow.com/questions/7930577
复制相似问题