5

尝试使用 打印包含表格的 html 页面UIMarkupTextPrintFormatter。出于某种奇怪的原因,当第一页上有足够的空间(2-3 英寸)时,最后一行会被推到第二页。更糟糕的是,当我从 html 表中删除最后一行时,现在的最后一行(比删除的行长几英寸)在第 1 页和第 2 页之间拆分,当它在删除行之前清楚地适合第 1 页时。页眉和页脚高度都设置为零。插图也为零。使用 UIWebView 并使用打印时,相同的 html 非常适合 1 页 UIViewPrintFormatter *formatter = [webview viewPrintFormatter]; 但这需要显示 UIWebView(因此它会被渲染),我不想这样做。

对此的任何见解将不胜感激。

4

1 回答 1

0

In a similar situation, but with a fixed size of my html table this worked for me:

    formatter.maximumContentWidth = 10. * 72.;

might be not the most elegant solution, you would have to adjust the parameters (i.e. make them dynamic) and check the paper size dependence:

    UIPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:html];
    formatter.startPage = 0;
    formatter.contentInsets = UIEdgeInsetsMake(36., 14., 0., 0.);

    // prevent to generate an extra blank page
    formatter.maximumContentWidth = 10. * 72.;

    ...
    [formatter release];
    // please note        
    printInfo.orientation = UIPrintInfoOrientationLandscape;
于 2013-04-07T08:36:58.860 回答