如何使用Flying Saucer XML / CSS渲染器生成的PDF标题空白处的文本对齐方式

时间:2018-12-03 16:27:19

标签: css flying-saucer

我正在Spring Boot应用程序中使用Flying Saucer 9.1.16 XML / CSS渲染器生成PDF。除了text-align以外,所有CSS属性都可以正常工作。这是我的CSS的摘录:

@page {
    size: landscape;
    margin-top: 100px;
    border-bottom: solid gray;

    @top-right{
        content: element(header-top);
        padding-top: 15px;
        text-align-last: end !important;
    }; 

    @bottom-right{
        content: element(pagination);
        vertical-align: top;
        text-align: right !important;
    };
}

那是HTML:

<div class="header-center text-primary">
     <h3 th:text="${ownerProperty}"></h3>
     <h4 th:text="${owner.ownerName}"></h4>
</div>

<div class="pagination text-muted">
     <small>
         <span  th:text="#{page} + '&nbsp;'"></span>
         <span id="pagenumber"></span>
         <span  th:text="#{of} + '&nbsp;'"></span>
         <span id="pagecount"></span>
     </small>
 </div>

我尝试了这两种方法,但没有成功: text-align-last: end !important;text-align: right !important;

我使用Thymeleaf作为模板引擎,除了CSS,PDF还链接了另外bootstrap.min.css个。

1 个答案:

答案 0 :(得分:1)

将带有CSS的HTML转换为pdf时,人们经常遇到问题。  您应该使用align属性来解决此问题。

<div align="right">
    Any text
</div>
<div align="center">
    Any text
</div>