ios html 调用打印机,在iOS中打印HTML

此刻,我正在使用以下代码进行打印。请注意,我有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的文档:顶部插图仅适用于打印内容的第一页。

1bJU9.png

我希望输出具有一致的边距,就像Safari产生的输出一样。

WwdTc.png

对此有何建议?

2011-05-06

Mustafa

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值