关于网络应用程序:Google Web应用程序HTML分页符不起作用

Google Web app HTML page break not working

我有一个Google Apps脚本" Web App "。我正在尝试为其生成的2页仪表板创建一个分页符。

我已经用此处发布的基本Web应用程序重现了该问题,这里是完整的代码。

1
2
3
4
5
6
7
8
9
10
11
12
<body>
page1

page2
</body>

<style>
.break{
display:block;
page-break-before:always;
}
</style>

是因为Web应用程序显示在单个iframe中,所以无法中断吗?

如果可以-是否可以将其拆分为多个iframe?

还是我想念的简单东西。

编辑:我现在也尝试过

1
2
3
4
div.break{
 display:block;
 page-break-before:always;
}

1
2
3
4
5
6
@media print {
 div.break{
 display:block;
 page-break-before:always;
 }
}

那并没有改变任何东西。我已经在Chrome浏览器中尝试过


是的,您的html由Google Apps脚本显示在iframe中。当您尝试打印Web应用程序页面时,无法在多个页面中打印此iframe

解决方案:在Web应用程序中选择一些文本,例如page1,以获取iframe的上下文,然后单击Print ...,它将只打印您在以下位置选择的iframe文本:

enter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
page1

page2

<!-- added print button (with class"hide-on-print" to not display it when printed) -->
<button id="print" class="hide-on-print">Print...</button>


// open print dialog on button click
document.getElementById('print').addEventListener('click', function(){
  window.print();
});


<style>
@media print {
    .hide-on-print {
        display: none
    }
    .break{
      display:block;
      page-break-before:always;
    }
}
</style>


首先,必须感谢Kos指出,如果我在iframe中突出显示文本,然后可以正确打印-我从没想过要尝试

所以现在我添加了一个小功能,仅打印iframe而不是页面本身。

1
2
3
4
function printall() {
 window.print();
 window.frames[0].print();
}

,我已经在该功能的仪表板上添加了一个按钮。我只是确保用户不使用常规的打印菜单。


请使用@media print {div.break {}}尝试。