Skip to content Skip to sidebar Skip to footer

Huge White Space After Header In Pdf Using Flying Saucer

I am trying to export an HTML page into a PDF using Flying Saucer. For some reason, the pages have a large white space after the header (id = 'divTemplateHeaderPage1') divisions.

Solution 1:

Please take a look at the metadata of your PDF:

enter image description here

You are using an old third party tool that is not endorsed by iText Group, and that uses iText 2.1.7, a version of iText dating from 2009 that should no longer be used.

It would probably have been OK to complain and to write "My code isn't working" about 7 years ago, but if you would use the most recent version of iText, the result of converting your HTML to PDF would look like this:

enter image description here

I only needed a single line of code to get this result:

HtmlConverter.convertToPdf(new File(src), new File(dest));

In this line src is the path the the source HTML and dest is the path to the resulting PDF.

I only had to apply one minor change to your HTML. I change the @page properties like this:

@page {
  size: 27cm38cm;
  margin: 0.2cm;
}

If I hadn't changed this part of the CSS, the page size would have been A4, and in that case, not all the content would have fitted the page. I also added a small margin because I didn't like the fact that the border was sticking to close to the sides of the page.

Morale: don't use old versions of libraries! Download the latest version of iText and the pdfHTML add-on. You need iText 7 core and the pdfHTML add-on. You might also want to read the HTML to PDF tutorial.

Post a Comment for "Huge White Space After Header In Pdf Using Flying Saucer"