我使用以下代碼打印包含文本和圖像的HTML內容。打印紙張大小和內容
if (![UIPrintInteractionController isPrintingAvailable]) {
UIAlertView *alertView = [[[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Printer Availability Error Title", @"")
message:NSLocalizedString(@"Printer Availability Error Message", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
otherButtonTitles:nil] autorelease];
[alertView show];
return;
}
UIPrintInteractionController *pic =
[UIPrintInteractionController sharedPrintController];
if(!pic) {
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"Sample";
pic.printInfo = printInfo;
NSString *htmlString = [self prepareHTMLText];
UIMarkupTextPrintFormatter *htmlFormatter =
[[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString];
htmlFormatter.startPage = 0;
// 1-inch margins on all sides
htmlFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
// printed content should be 6-inches wide within those margins
htmlFormatter.maximumContentWidth = 6 * 72.0;
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];
}
查看附件的結果(縮小版本可能不是很清楚,但希望你能得到圖片)。
這裏是我的問題:
如何在打印紙的尺寸由AirPrint的決定?如果我想特別格式化和打印A4紙的數據會怎麼樣?
使用上面的代碼和使用不同的模擬打印機(打印機模擬器)打印的結果是,在所有情況下,我在第一頁的頂部獲得1英寸的邊距,但不是在連續的頁面上。爲什麼?
使用上面的代碼和使用不同的模擬打印機(打印機模擬器)打印的結果是,在某些情況下,字體樣式會丟失。結果,內容向下移動。爲什麼?
如何返回A4紙張尺寸? – 2016-10-14 14:55:38