Печать файла PDF с Какао, сбой приложения

Я использую этот код для печати файла 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

Любая помощь будет высоко ценится

1 ответ

    // Create the document reference.
PDFDocument *pdfDocument = [[PDFDocument alloc] initWithURL: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];


PDFPrintScalingMode scale = kPDFPrintPageScaleDownToFit;

// Grab the returned print operation.
NSPrintOperation *op = [pdfDocument printOperationForPrintInfo: printInfo scalingMode: scale autoRotate: YES];

// Run the print operation without showing any dialogs.
[op setShowsPrintPanel:NO];
[op setShowsProgressPanel:NO];
[op runOperation];

это должно работать!!

Другие вопросы по тегам