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?