HTML import - footer problems

Our company product uses LibreOffice Writer to convert HTML documents into PDF, using a scripted command line.

This works fine for most simple HTML formatting things we need to use for client documents, but recently one client wants the facility to have page footers (add only a footer to first page of document).

I am trying to generate the correct HTML to do this, and I am having awful trouble. Either the footer appears on first page and then every second page after that (1, 3, 5 etc.), or it appears on second page and every second one after that (2, 4, 6 etc.)

Example:

Start off with simple HTML generated by LibreOffice export of 4 pages.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1252"/>
  <title></title>
  <meta name="generator" content="LibreOffice 6.3.3.2 (Windows)"/>
  <meta name="created" content="2020-01-06T15:11:32.647000000"/>
  <meta name="changed" content="2020-01-06T15:14:16.935000000"/>
  <style type="text/css">
    @page { size: 21cm 29.7cm; margin: 2cm }
    @page:first { }
    p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
  </style>
</head>
<body lang="en-IE" link="#000080" vlink="#800000" dir="ltr"><p style="margin-bottom: 0cm; line-height: 100%">
Page 1</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 2</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 3</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 4</p>
</body>
</html>

The way I add footer to HTML is the same as OpenOffice does on export, add a DIV with class “footer” to end of HTML page.

<div title="footer">
<p style="margin-top: 0.5cm; margin-bottom: 0cm; line-height: 100%">TEST NORMAL FOOTER</p>
</div>

so it becomes:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1252"/>
  <title></title>
  <meta name="generator" content="LibreOffice 6.3.3.2 (Windows)"/>
  <meta name="created" content="2020-01-06T15:11:32.647000000"/>
  <meta name="changed" content="2020-01-06T15:14:16.935000000"/>
  <style type="text/css">
    @page { size: 21cm 29.7cm; margin: 2cm }
    @page:first { }
    p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
  </style>
</head>
<body lang="en-IE" link="#000080" vlink="#800000" dir="ltr"><p style="margin-bottom: 0cm; line-height: 100%">
Page 1</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 2</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 3</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 4</p>

<div title="footer">
<p style="margin-top: 0.5cm; margin-bottom: 0cm; line-height: 100%">TEST NORMAL FOOTER</p>
</div>

</body>
</html>

This single addition appears to cause LibreOffice to add footer to pages 2, 4, 6 etc.

Removing the header style

@page:first { } 

from HTML causes it to shift footer to pages 1, 3, 5 etc.

ie.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1252"/>
  <title></title>
  <meta name="generator" content="LibreOffice 6.3.3.2 (Windows)"/>
  <meta name="created" content="2020-01-06T15:11:32.647000000"/>
  <meta name="changed" content="2020-01-06T15:14:16.935000000"/>
  <style type="text/css">
    @page { size: 21cm 29.7cm; margin: 2cm }
    p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
  </style>
</head>
<body lang="en-IE" link="#000080" vlink="#800000" dir="ltr"><p style="margin-bottom: 0cm; line-height: 100%">
Page 1</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 2</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 3</p>
<p style="margin-bottom: 0cm; line-height: 100%; page-break-before: always">
Page 4</p>

<div title="footer">
<p style="margin-top: 0.5cm; margin-bottom: 0cm; line-height: 100%">TEST NORMAL FOOTER</p>
</div>

</body>
</html>

I realise this all works correctly when the document is an original LibreOffice ODT in which I can change the page class of the first page to “First Page” and then add footer to that class only, but this does not work in “HTML” mode, where ALL pages end up with same HTML class on load of HTML document. But we can’t export ODT format from our application. We only use HTML export.

So… what I would like to know is… how do I tell it to put the footer on first page only, and not on every second page?

Is there some extra HTML tags I could add?

I did try adding a

class=“first page”

to the footer, but it didn’t work.

I also don’t understand why it is currently not actually adding the same footer to all pages?

This is the reverse of page numbering we normally meet. In documents you often have no page number or heading/footer on the first heading and introduction pages, then numbering headings/footings on the main part of the document. The technique is the same i both cases.

These page options are controlled by the PAGE STYLES. Normally on a HTML document you just have the one page style called HTML. The default for the next style is HTML. I assume, in this case, you should set the first page (FIRST PAGE) to give a footer, and define a second style, (BODY PAGE) without footer.

This second style (BODY PAGE) should also invoke the second style (BODY PAGE) in the next style option.

To view the existing page style you can right click on the document.

By the way, are you using TEXT or HTML to create the new document.

It is worth a little time to explore the use of styles. This will save a lot of effort.

You problem on page numbering is caused by right side pages being ODD numbers, left being EVEN. Look at any book. If you need different headings or footings on odd and even pages, you will need two body page styles.

Hope this helps.

I’m not sure I’m understanding what you are saying to do.

Are you adding all these page style manually using Writer after the document is loaded or something?

The problem I am having is that the document is a HTML document being imported so I have to somehow define these page styles in the actual HTML source and have LibreOffice Writer use them.

I have not been able to find HTML code that it will read and set a footer only on first page only. Or even to tell it to put footer on all pages.

Obviously it is easy to manually add all these page styles and footers in LibreOffice after any document is loaded - but that’s no use during HTML document import.

Had the same problem. My goal was to add footer on all pages. Adding footer twice helped me. I don’t know why

<div title="footer">
<p style="margin-top: 0.5cm; margin-bottom: 0cm; line-height: 100%">TEST NORMAL FOOTER</p>
</div>  
<div title="footer">
<p style="margin-top: 0.5cm; margin-bottom: 0cm; line-height: 100%">TEST NORMAL FOOTER</p>
</div>