【问题标题】:Paginating in Pisa (xhtml2pdf) just repeats last page在比萨(xhtml2pdf)中分页只是重复最后一页
【发布时间】:2012-11-23 03:11:29
【问题描述】:

我正在使用 Pisa 生成一个 PDF 文件,其中的页面遵循通用格式。 当我生成 PDF(从命令行或从 python API)时,我显然做错了什么,我只看到最后一页重复。

在下面的代码上运行比萨,我得到三个页面,每个页面都显示“C 星期三”,而我希望看到三个不同的页面,分别是“A 星期一”、“B 星期二”、“C 星期三”。

我当前的 Pisa 版本是XHTML2PDF/pisa 3.0.33 (Build 2010-06-16)

<html>
<style>
    /* 297 x 210 */
@page {
  size: a4 landscape;
  margin: 1cm;
  margin-bottom: 2.5cm;

  @frame header {
    -pdf-frame-content: headerContent;
    background-color:black;
    color:white;
    top : 0cm;
    margin-left: 0cm;
    margin-right: 14.5cm; 
    height: 2.5cm;
    width: 14.9cm;
  }

  @frame lhs {
    -pdf-frame-content: lhs;
    background-color:white;
    color:black;
    top : 4.5cm;
    margin-left: 0cm;
    margin-right: 14.5cm; 
    height: 13.5cm;
    width: 14.9cm;
  }

  @frame footer {
    -pdf-frame-content: footerContent;
    color:black;
    bottom: 1cm;
    margin-left: 1cm;
    margin-right: 24.5cm; 
    height: 1cm;
  }

}

body {
}

#headerContent {
    text-align: center;
    background-color: black;
    color: white;
}
h1 {
    font-size: 200%;
}

#lhs-table {
    color:black;
    text-align: center;
    font-size:600%;
}

.big {
    font-size:200%;
    font-style:italic;
}

.day {
    text-align: center;
    background-color: black;
    color: white;
    width: 1.6cm;
    height: 1.3cm;
}

#footerContent {
    font-size: 200%;
}


</style>
<body>

<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>A</em></span></td>
                </tr>
            </table>
    </div>

  <div id="footerContent">
      <span class="day" >Monday</span>
  </div>

  </div>
    <pdf:nextpage />


<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>B</em></span></td>
                </tr>
            </table>
    </div>


  <div id="footerContent">
      <span class="day" >Tuesday</span>
  </div>

  </div>
    <pdf:nextpage />


<div>
  <div id="headerContent">
      <h1><br/>HEADER<br/></h1>
  </div>

  <div id="lhs">
      <table id="lhs-table" >
                <tr>
                    <td><span class="big"><em>C</em></span></td>
                </tr>
            </table>
    </div>

  <div id="footerContent">
      <span class="day" >Wednesday</span>
  </div>

  </div>
    <pdf:nextpage />


</body>
</html>

【问题讨论】:

    标签: python pisa xhtml2pdf


    【解决方案1】:

    从 Github 尝试版本https://github.com/chrisglass/xhtml2pdf 您的版本太旧且无人维护。

    关于您的问题,是解析器中的一个已知问题。尝试像这样将标签放在自己的行上:

    <div id="footer">
         <pdf:pagenumber />
    </div>
    

    三读后:

    <body>
    <div id="header">
    </div>
    
     <div id="content1>
       content 1
     </div>
     <pdf:nextpage />
    
     <div id="content2>
         content 2
     </div>
     <pdf:nextpage />
    
     <div id="content3>
         content 3
     </div>
     <pdf:nextpage />
    
    <div id="footer">
    </div>
    </body>
    

    从您的代码中,您正在为每个内容重复页眉和页脚。但是您已将它们定义为标题框架(在每一页上自动重复它们),因此解析器一定要疯了。此外,您正在为内容创建另一个静态框架,这不应该。

    所以,只有一个页眉,一个页脚,创建很多内容,后面有&lt;pdf:nextpage /&gt;

    https://github.com/chrisglass/xhtml2pdf/blob/master/doc/usage.rst

    也许我又把你理解错了,因为我不知道你是如何生成这个 html 的。

    【讨论】:

    • 我刚刚按照您的建议尝试了 git 存储库中的最新版本,但我仍然得到相同的行为。
    • 添加了回答的解释。
    • 这种方法我也没有运气。您发布了一个简单的工作示例?
    • 伙计,对不起,我不明白你的问题。我即将重写我的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2011-02-20
    • 1970-01-01
    相关资源
    最近更新 更多