我正在使用此代码打印 Pdf 文件:
- (void)printPDF:(NSURL *)fileURL {
// Create the print settings.
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setTopMargin:0.0];
[printInfo setBottomMargin:0.0];
[printInfo setLeftMargin:0.0];
[printInfo setRightMargin:0.0];
[printInfo setHorizontalPagination:NSFitPagination];
[printInfo setVerticalPagination:NSFitPagination];
// Create the document reference.
PDFDocument *pdfDocument = [[PDFDocument alloc] initWithURL:fileURL];
// Invoke private method.
// NOTE: Use NSInvocation because one argument is a BOOL type. Alternately, you could declare the method in a category and just call it.
BOOL autoRotate = YES;
NSMethodSignature *signature = [PDFDocument instanceMethodSignatureForSelector:@selector(getPrintOperationForPrintInfo:autoRotate:)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:@selector(getPrintOperationForPrintInfo:autoRotate:)];
[invocation setArgument:&printInfo atIndex:2];
[invocation setArgument:&autoRotate atIndex:3];
[invocation invokeWithTarget:pdfDocument];
// Grab the returned print operation.
NSPrintOperation *op = nil;
[invocation getReturnValue:&op];
// Run the print operation without showing any dialogs.
[op setShowsPrintPanel:NO];
[op setShowsProgressPanel:NO];
[op runOperation];
}
我的代码中也有这个:
- (NSPrintOperation *)getPrintOperationForPrintInfo:(NSPrintInfo *)printInfo autoRotate:(BOOL)doRotate;
{
return nil;
}
它打印 Pdf 文件,但应用程序总是崩溃......我想有什么东西不见了
(NSPrintOperation *)getPrintOperationForPrintInfo
任何帮助都感激不尽