title: LibreOffice: Text for footer of last page
body: <p>I want to create a custom LibreOffice Writer template of our company. This template should include a disclamer in the footer of the last page of each document.</p>
  
  <p>In our existing M$ Word template we use a field with "IF({current page}={last page};...", but LibreOffice seems not to be able to use the current page number in conditional texts.
  The <a href="https://help.libreoffice.org/Writer/Defining_Conditions" rel="nofollow">LibreOffice Help page</a> says: </p>
  
  <blockquote>
    <p>You cannot use internal variables, such as page and chapter numbers, in condition expression.</p>
  </blockquote>
  
  <p>Using a custom page style for the last page also seems not to be a good decision, because if someone inserts too much content into that "last page" and causes an automatic page break then he gets the disclamer twice.</p>
  
  <p>How can I create a footer in LibreOffice that will automatically be shown on the last page of a document, but not on any other page?</p>
  
  <hr>
  
  <p>edit: I managed to write a macro that can insert a page break for the last page. Still not the complete solution, but might be a way to go:</p>
  
  <pre><code>Sub PageBreakForLastPage
  
    ' create cursor
    Cursor = ThisComponent.CurrentController.getViewCursor
  
    ' move to start of last page
    Cursor.jumpToLastPage
    Cursor.jumpToStartOfPage
  
    ' create page break
    Cursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
    Cursor.PageDescName = "First Page"
  
  End Sub
  </code></pre>