我正在使用Flying Saucer R8生成PDF文件.PDF需要一个标题,将在每个页面上重复.标题将由用户指定,因此我无法确定它的高度.我设法在每个页面上重复标题,但问题是如果标题有多行文本,它不会动态重新调整正文的高度,最终会重叠它.这是我的代码:
<!DOCTYPE html>
<html>
<head>
<style>
@page {
size: 4.18in 6.88in;
margin: 0.25in;
@top-center {content: element(header);}
}
#header {
color: red;
display: block;
position: running(header);
}
</style>
</head>
<body>
<div id="header">
<-- Lots of text here -->
</div>
<div class="section">
<-- Lots of text here -->
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用Flying Saucer生成后生成的PDF如下所示:

任何人都可以帮我找到一个解决方案,我的头部不要与身体的其他部分重叠?
我有一个单击按钮就调用的函数,它需要很长时间才能创建一些元素并将其附加到DOM,所以我想在函数完成操作后显示带有“正在加载”图标的PopupPanel。做。请注意,我的函数不会调用服务器,它只会在UI中创建一些元素,这些元素需要很长时间才能计算出来,因此我没有onSuccess()事件或回调函数。
所以我有我的PopupPanel:
pp = new PopupPanel();
pp.setTitle("loading....");
pp.setGlassEnabled(true);
Run Code Online (Sandbox Code Playgroud)
然后在点击处理程序上,我有以下代码:
public void onClick(ClickEvent event) {
pp.show();
functionWhichTakesaLongTimeToExecute();
pp.hide();
}
Run Code Online (Sandbox Code Playgroud)
由于JavaScript是单线程的,因此我期望PopUp会出现,然后执行functionWhichTakesaLongTimeToExecute(),然后将PopUp隐藏,但是发生的是首先执行functionWhichTakesaLongTimeToExecute(),这需要很长时间才能将元素附加到DOM,并且只有在完成工作后才显示PopUp,然后将其隐藏。好像代码是:
functionWhichTakesaLongTimeToExecute();
pp.show();
pp.hide();
Run Code Online (Sandbox Code Playgroud)
更让我困扰的是,如果我在pp.show()之后添加Window.alert(“ test”),这将中断流程,直到按下警报中的“确定”按钮,这会导致PopUp出现在警报和在调用functionWhichTakesaLongTimeToExecute()之前。因此,以下代码按预期工作:
pp.show();
Window.alert("test");
functionWhichTakesaLongTimeToExecute();
pp.hide();
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么在调用functionWhichTakesaLongTimeToExecute()之前为什么不显示PopUp,而是“等待” functionWhichTakesaLongTimeToExecute()执行,直到它显示之后,以及为什么添加Window.alert(“ test ”)使其正确显示?
PS:我已经在IE8和Chrome中测试了代码,并且行为相同。