manualpagebreak.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2012 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. # This example shows how to create a manual page break.
  21. from odf.opendocument import OpenDocumentText
  22. from odf.style import Style, TextProperties, ParagraphProperties
  23. from odf.text import P
  24. textdoc = OpenDocumentText()
  25. # Create a style for the paragraph with page-break
  26. withbreak = Style(name="WithBreak", parentstylename="Standard", family="paragraph")
  27. withbreak.addElement(ParagraphProperties(breakbefore="page"))
  28. textdoc.automaticstyles.addElement(withbreak)
  29. p = P(text=u'First paragraph')
  30. textdoc.text.addElement(p)
  31. p = P(stylename=withbreak,text=u'Second paragraph')
  32. textdoc.text.addElement(p)
  33. textdoc.save("pagebreak_odfpy.odt")