html - 从 CSS 和 HTML 生成 PDF,@page @top-center 和内容之间的距离更大

标签 html css pdf pdf-generation css-paged-media

我使用 ITextRenderer 从 CSS 和 HTML 生成 PDF。但我不知道如何在 9 之间增加距离。一些文本和@top-center 的 border-bottom。

这是我的样式:

@page {
  counter-increment: page; 
  margin-top: 80px;
  @top-center { 
    font-size: 9pt;
    content: "Page Header";
    border-bottom: 2px solid black;
    white-space: pre; 
    margin-bottom: 40px;
  }
}

现在是这样的: a http://oi58.tinypic.com/fmto5d.jpg

这就是我要找的结果。

a http://oi57.tinypic.com/sl09oi.jpg

最佳答案

您需要在@page 定义中增加margin-top。边距框受@page 定义赋予它们的空间量的限制。

编辑:如果设置@top-center 框的高度会怎样?

根据 the specification ,您的代码应该可以工作。 我在我的样式表中使用了类似的东西,当我用 Antennahouse 渲染它时它起作用了:

@page portrait {
    size: Letter;
    margin-top: 28mm;
    margin-bottom: 28mm;
    margin-left: 25.4mm;
    margin-right: 25.4mm;
       @top-left {
        font-size: 9pt;
        font-family: Arial, sans-serif;
        border-bottom: 0.5pt solid black;
        margin-bottom: 10mm;
        vertical-align: bottom;
        padding-bottom: 1mm;
        content: "Header"; 
    } 
}

关于html - 从 CSS 和 HTML 生成 PDF,@page @top-center 和内容之间的距离更大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29237096/

相关文章:

html - 比 <aside> 更好的放置广告的元素

html - QT html和CSS转pdf文件

html - nth-child 可以与此 HTML 结构一起使用吗?

php - 自定义 wordpress 主题

pdf - 使用 pypdf 更改 pdf 文件的元数据

javascript - jQuery 使用 .animate 滚动到顶部 - 先跳到底部?

iphone - Objective C HTML 转义/取消转义

java - Android - Jar 集成 - Dalvik 错误 1 ​​或无法解析父类(super class)

c# - 如何从 Web API 应用程序返回 PDF

html - 字体在浏览器中呈现不统一