我已经使用此功能成功打印了一张PDF:
-(void)printPDF{
NSString* fileName = @"Certificate.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) NSLog(@"Print error: %@", error);
};
NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];
printController.printingItem = pdfData;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[printController presentFromRect:self.btnPrint.frame inView:self.btnPrint.superview
animated:YES completionHandler:completionHandler];
} else {
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
当我想打印几张PDF时,我已经放入了一个阵列(证书)。在我选择打印机之前,printController对话框消失了,我收到以下错误。 "警告:正在进行演示或解雇时尝试从视图控制器中解除!"
我是否需要为printcontroller使用一些delgate方法,或者什么是catch?
这是我尝试打印多个PDF文档。
-(void)printAllPDF{
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error) NSLog(@"Print error: %@", error);
};
printController.printingItems = certificates;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[printController presentFromRect:self.btnPrintAll.frame inView:self.btnPrintAll.superview
animated:YES completionHandler:completionHandler];
} else {
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
答案 0 :(得分:0)
我很糟糕......我应该花更多时间调试。
我实际上是在我的“数组循环”中调用PrintPDF ... 起来......对不起: - (
- (IBAction)fcPrintAllBtn:(UIButton *)sender {
[certificates removeAllObjects];
for (Paxtype *pax in paxArray) {
[self createPDFWithPax:pax Balloon:self.edtFlightBalloon.text Landing:self.edtLandingSite.text Date:self.edtFlightDate.text Gender:pax.sBookGender PaxTitle:self.edtPaxTitle.text Start:self.edtLaunchSite.text Speed:self.edtMaxSpeed.text Altitude:self.edtMaxAlt.text
Distance:self.edtDistance.text];
NSString* fileName = @"Certificate.PDF";
NSArray *arrayPaths =
NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [arrayPaths objectAtIndex:0];
NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
NSData *pdfData = [[NSFileManager defaultManager] contentsAtPath:pdfFileName];
[certificates addObject:pdfData];
[self printAllPDF]; <-----This should not be here !!!
}
[self printAllPDF]; <-----But here !!
NSLog(@"Certificates %i", certificates.count);
}