Appleの印刷ドキュメントの例を使用して、iPhoneからAirprint互換プリンターにPDFを印刷しています。しかし、私はiPhoneから全ページ印刷を取得していません.私が取得しているものの写真を見てください.PDFを紙の長さ、幅全体に印刷する必要があります.
印刷機能に使用しているコードを以下に示します。Apple 印刷サンプル アプリと同じコードです。
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};
controller.delegate = self;
// Obtain a printInfo so that we can set our printing defaults.
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
// This application produces General content that contains color.
printInfo.outputType = UIPrintInfoOutputGeneral;
// We'll use the URL as the job name.
printInfo.jobName = [_filePath lastPathComponent];
// Set duplex so that it is available if the printer supports it. We are
// performing portrait printing so we want to duplex along the long edge.
printInfo.duplex = UIPrintInfoDuplexLongEdge;
// Use this printInfo for this print job.
controller.printInfo = printInfo;
controller.printingItem = myData;
// Be sure the page range controls are present for documents of > 1 page.
controller.showsPageRange = YES;
// This code uses a custom UIPrintPageRenderer so that it can draw a header and footer.
APLPrintPageRenderer *myRenderer = [[APLPrintPageRenderer alloc] init];
// UIPrintPageRenderer *myRenderer = [[UIPrintPageRenderer alloc] init];
// The APLPrintPageRenderer class provides a jobtitle that it will label each page with.
// myRenderer.jobTitle = printInfo.jobName;
// To draw the content of each page, a UIViewPrintFormatter is used.
UIViewPrintFormatter *viewFormatter = [docWebView viewPrintFormatter];
#if SIMPLE_LAYOUT
UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT];
CGSize titleSize = [myRenderer.jobTitle sizeWithFont:font];
myRenderer.headerHeight = myRenderer.footerHeight = titleSize.height + HEADER_FOOTER_MARGIN_PADDING;
#endif
[myRenderer addPrintFormatter:viewFormatter startingAtPageAtIndex:0];
// Set our custom renderer as the printPageRenderer for the print job.
controller.printPageRenderer = myRenderer;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[controller presentFromBarButtonItem:sender animated:YES completionHandler:completionHandler]; // iPad
}
else
{
docWebView.hidden = YES;
[controller presentAnimated:YES completionHandler:completionHandler]; // iPhone
}