使用AirPrint在连续纸卷上打印时多余的空白空间

静态的

我正在研究使用票据打印机将票据打印到连续纸卷上的代码。收据类似于您在商店中用信用卡付款时得到的收据。

我正在使用UIMarkupTextPrintFormatter,如下面的代码所示。

但是由于某种原因,我在打印文本的中间和结尾都一直保持空白。(在打印最后一行之后,打印机将继续滚动几英寸的白纸!)

我检查了pageCount属性,它返回2,所以可能这是多余的空白来自哪里。

我还启用了页面范围以显示页面数(用于调试)。我不应该在控制器上获得页面范围。但是我的意思是我的内容超过2页。

您能否指出我的代码不足之处?将HTML内容打印到连续纸上的正确方法是什么?

我的代码可以在打印机模拟器上完美运行。我得到了我想要的确切输出。没有意外的空格。但是在与AirPrint兼容的真实收据打印机上却失败了!

任何建议都非常感谢。

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
    DDLogInfo(@"Couldn't get shared UIPrintInteractionController!");
    return;
}

UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if(!completed && error)
        DDLogInfo(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
};

controller.showsPageRange = YES;
controller.showsPaperSelectionForLoadedPapers = YES;

//  Since the we're using a formatter, explicitly set the other properties to nil
controller.printingItem = nil;
controller.printingItems = nil;
controller.printPageRenderer = nil;


UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:[self htmlPrintContent]];
formatter.startPage = 0;
formatter.contentInsets = UIEdgeInsetsZero;
controller.printFormatter = formatter;

// Ask for a print job object and configure its settings to tailor the print request
UIPrintInfo *info = [UIPrintInfo printInfo];

// B&W or color, normal quality output for mixed text, graphics, and images
info.outputType = UIPrintInfoOutputGrayscale;

// Select the job named this in the printer queue to cancel our print request.
info.jobName = @"somejobname";

// Make sure we are printing in a portrait orientation.
info.orientation = UIPrintInfoOrientationPortrait;

// We don't need duplex printing so set it to none explicitly
info.duplex = UIPrintInfoDuplexNone;

// Instruct the printing concierge to use our custom print job settings.
controller.printInfo = info;


// Present the standard iOS Print Panel that allows you to pick the target Printer, number of pages, etc.
[controller presentFromRect:self.printButton.frame inView:self.view animated:YES completionHandler:completionHandler];
静态的

我最终切换到UISimpleTextPrintFormatter而不是UIMarkupTextPrintFormatter。

所有格式化均使用NSAttributedString完成

也已实施

- (CGFloat)printInteractionController:(UIPrintInteractionController *)printInteractionController cutLengthForPaper:(UIPrintPaper *)paper

为了确定我的文字所需的高度。

CGFloat printableWidth = paper.printableRect.size.width;

CGRect attributedStringBoundingRect = [attributedPrintContent boundingRectWithSize:CGSizeMake(printableWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil];

/* Calculate the margins of the roll */
CGFloat lengthOfMargins = paper.paperSize.height - paper.printableRect.size.height;

/* The cut length is the height of the text, plus margins, plus content insets */
CGFloat cutLength = attributedStringBoundingRect.size.height + lengthOfMargins + formatter.contentInsets.bottom + formatter.contentInsets.top;

希望这可以帮助...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用“ Aspose Words”在连续纸(纸卷)中打印可变高度的.DOC

来自分类Dev

ios-使用AirPrint打印HTML时出现字体问题

来自分类Dev

使用strpos时的多余空间点

来自分类Dev

使用drawable时如何删除按钮中的多余空间

来自分类Dev

Firefox打印CSS-A4页上的多余空白页

来自分类Dev

打印时总是有一个多余的空白页

来自分类Dev

打印时无需多余的空格

来自分类Dev

使用报表查看器进行打印预览会使多余的页面空白

来自分类Dev

在Windows命令行上设置变量时防止多余的空间

来自分类Dev

在bash开始时删除多余的空间

来自分类Dev

右页CSS / HTML上的多余空白

来自分类Dev

使用AirPrint打印Pdf会导致小输出

来自分类Dev

元素自动在页脚上方添加多余的空白空间

来自分类Dev

使用TextInputLayout和TextInputEditText时删除多余的空间/填充/边距

来自分类Dev

使用TextOverflow.ellipsis时如何删除文本右侧的多余空间

来自分类Dev

每次我使用php添加更多表时,顶部的多余空间

来自分类Dev

使用连续的空白xsl:text时,空白文本将从输出文件中删除

来自分类Dev

代码在输出中打印多余的空间并计算错误

来自分类Dev

当在堆上请求较大的内存块时,如果RAM上没有连续空间,是否在磁盘(交换)上分配了连续空间?

来自分类Dev

使用首字母删除多余的空白

来自分类Dev

使用CSS3创建纸卷

来自分类Dev

使用带有“行环绕”和Grid-gap的Angular Flex时,请删除底部的多余空间

来自分类Dev

如何摆脱“下拉菜单”上的多余空间?

来自分类Dev

Flutter:多行文本小部件上的多余空间

来自分类Dev

如何摆脱“下拉菜单”上的多余空间?

来自分类Dev

圆角的线性布局,在角上留有多余的空间

来自分类Dev

设置CSS高度和垂直滚动时多余的空间

来自分类Dev

当有多余空间时,如何使phpspreadsheet适应页面

来自分类Dev

处于移动模式时,主CSS多余的空间

Related 相关文章

  1. 1

    使用“ Aspose Words”在连续纸(纸卷)中打印可变高度的.DOC

  2. 2

    ios-使用AirPrint打印HTML时出现字体问题

  3. 3

    使用strpos时的多余空间点

  4. 4

    使用drawable时如何删除按钮中的多余空间

  5. 5

    Firefox打印CSS-A4页上的多余空白页

  6. 6

    打印时总是有一个多余的空白页

  7. 7

    打印时无需多余的空格

  8. 8

    使用报表查看器进行打印预览会使多余的页面空白

  9. 9

    在Windows命令行上设置变量时防止多余的空间

  10. 10

    在bash开始时删除多余的空间

  11. 11

    右页CSS / HTML上的多余空白

  12. 12

    使用AirPrint打印Pdf会导致小输出

  13. 13

    元素自动在页脚上方添加多余的空白空间

  14. 14

    使用TextInputLayout和TextInputEditText时删除多余的空间/填充/边距

  15. 15

    使用TextOverflow.ellipsis时如何删除文本右侧的多余空间

  16. 16

    每次我使用php添加更多表时,顶部的多余空间

  17. 17

    使用连续的空白xsl:text时,空白文本将从输出文件中删除

  18. 18

    代码在输出中打印多余的空间并计算错误

  19. 19

    当在堆上请求较大的内存块时,如果RAM上没有连续空间,是否在磁盘(交换)上分配了连续空间?

  20. 20

    使用首字母删除多余的空白

  21. 21

    使用CSS3创建纸卷

  22. 22

    使用带有“行环绕”和Grid-gap的Angular Flex时,请删除底部的多余空间

  23. 23

    如何摆脱“下拉菜单”上的多余空间?

  24. 24

    Flutter:多行文本小部件上的多余空间

  25. 25

    如何摆脱“下拉菜单”上的多余空间?

  26. 26

    圆角的线性布局,在角上留有多余的空间

  27. 27

    设置CSS高度和垂直滚动时多余的空间

  28. 28

    当有多余空间时,如何使phpspreadsheet适应页面

  29. 29

    处于移动模式时,主CSS多余的空间

热门标签

归档