作成したPDFを印刷できるアプリを開発中です。PDF は 11 x 8.5 であるため、横向きモードで印刷する必要がありますが、向きを正しく設定するのに問題があります。プリント用に用意したものはこちら。
- (void)printit {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:selectedCountry];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
if (pic && [UIPrintInteractionController canPrintData:pdfData] ) {
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = selectedCountry;
printInfo.duplex = UIPrintInfoDuplexNone;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = pdfData;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error)
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
};
//if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [pic presentFromBarButtonItem:self.printButton animated:YES
// completionHandler:completionHandler];
// }
// else {
[pic presentAnimated:YES completionHandler:completionHandler];
// }
}
}