Search code examples
pdfpdf-generationflying-saucer

Table Header not displaying text in second page while generating PDF in v 9.1.20


We are using latest version of flying saucer v 9.1.20 , In that the table header is displaying correctly on first page with text , but it seems to be broken in remaining pages, header is repeated but the text is not visible.

We have also used property -fs-table-paginate: paginate in our code , but still the header text appears to be blank in pages

We have also tried with previous versions, and it works till version 9.1.15. Have anyone faced this issue, kindly let us know the solution for this.

Have also attached the screen shots of sample PDF and code that we have used.

Sample Code :

<style>
table {
  -fs-table-paginate: paginate;
}
</style>

<table style="width:20%;" border="1">
  <thead style="background: #222; color: #fff;">
    <tr>
      <td>Header 1</td>
      <td>Header 2</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
    <tr>
      <td>test html</td>
      <td>test html</td>
    </tr>
  </tbody>
</table>

enter image description here


Solution

  • This works for me with version 9.1.20 of flying-saucer.

    The jar was added through maven:

    <dependency>
        <groupId>org.xhtmlrenderer</groupId>
        <artifactId>flying-saucer-pdf</artifactId>
        <version>9.1.20</version>
    </dependency>
    

    Maven dependencies

    [INFO] ------------------------< org.example:SO-temp >------------------------
    [INFO] Building SO-temp 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO]
    [INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ SO-temp ---
    [INFO]
    [INFO] The following files have been resolved:
    [INFO]    org.bouncycastle:bctsp-jdk14:jar:1.46:compile
    [INFO]    org.xhtmlrenderer:flying-saucer-pdf:jar:9.1.20:compile
    [INFO]    org.xhtmlrenderer:flying-saucer-core:jar:9.1.20:compile
    [INFO]    com.lowagie:itext:jar:2.1.7:compile
    [INFO]    org.bouncycastle:bcmail-jdk14:jar:1.64:compile
    [INFO]    org.bouncycastle:bcpkix-jdk14:jar:1.64:compile
    [INFO]    org.bouncycastle:bcprov-jdk14:jar:1.64:compile
    

    Java part

    public class SO {
    
        public static void main(String[] args) throws Exception {
            String html = String.join("\n", Files.readAllLines(Paths.get("so.html"), StandardCharsets.UTF_8));
            ITextRenderer renderer = new ITextRenderer();
            OutputStream out = new FileOutputStream(new File("so.pdf"));
            renderer.setDocumentFromString(html);
            renderer.layout();
            renderer.createPDF(out);
            out.close();
        }
    }
    

    HTML Part

    <html>
    <head>
        <style  type="text/css">
            table {-fs-table-paginate: paginate;}
        </style>
    </head>
    <body>
    <table style="width:20%;" border="1">
        <thead style="background: #222; color: #fff;">
        <tr><td>Header 1</td><td>Header 2</td></tr>
        </thead>
        <tbody>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
        <tr><td>test html</td><td>test html</td></tr>
    
        </tbody>
    </table>
    </body>
    </html>