We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question
0

HTML import - footer problems

asked 2020-01-06 16:55:14 +0200

geogan gravatar image

updated 2020-10-12 00:12:57 +0200

Alex Kemp gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2020-11-19 18:49:11 +0200

N gravatar image

updated 2020-11-19 20:29:17 +0200

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>
edit flag offensive delete link more
0

answered 2020-01-07 17:00:58 +0200

petermau gravatar image

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.

edit flag offensive delete link more

Comments

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.

geogan gravatar imagegeogan ( 2020-01-08 18:43:54 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-01-06 16:55:14 +0200

Seen: 208 times

Last updated: Nov 19 '20