I trying to print a pdf with UIPrintInteractionController
that it load in the UIWevView
. The good news is that i can print the bad is that the output of the print is to small.
any help would be appreciated :)
- (IBACTION) printPDF {
if ((!_webView)) return;
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %ld",
error.domain, (long)error.code);
}
};
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
_webView.scalesPageToFit = NO;
UIViewPrintFormatter *viewFormatter = [_webView viewPrintFormatter];
viewFormatter.startPage = 0;
controller.printFormatter = viewFormatter;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
/* [controller presentFromBarButtonItem:printButton animated:YES completionHandler:completionHandler]; */
}else
[controller presentAnimated:YES completionHandler:completionHandler];
}
the output:
If found the solution by avoid printing form IUWebView
. I directly download the PDF in NSData format.
_data represente the NSData that i download by a request.
if (_data) {
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
//printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
printController.printingItem = _data;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %lu", error.domain, (long)error.code);
}
};
[printController presentAnimated:YES completionHandler:completionHandler];
}