此刻,我正在使用以下代码进行打印。请注意,我有HTML打印的要求。在iOS中打印HTML
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Sample";
pic.printInfo = printInfo;
NSString *htmlString = [self prepareHTMLEmailMessage];
UIMarkupTextPrintFormatter *htmlFormatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString];
htmlFormatter.startPage = 0;
htmlFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1-inch margins on all sides
htmlFormatter.maximumContentWidth = 6 * 72.0; // printed content should be 6-inches wide within those margins
pic.printFormatter = htmlFormatter;
[htmlFormatter release];
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[pic presentFromBarButtonItem:self.myPrintBarButton animated:YES completionHandler:completionHandler];
} else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
产生的结果并不能为所有页面提供一致的边距。部分问题是contentInsets属性。根据Apple的文档:顶部插图仅适用于打印内容的第一页。
我希望输出具有一致的边距,就像Safari产生的输出一样。
对此有何建议?
2011-05-06
Mustafa