Skip to content
jbh4x82 edited this page Jul 30, 2021 · 4 revisions

Landscape layout with headers and footers:

from odf.opendocument import OpenDocumentText from odf.style import PageLayout, MasterPage, Header, Footer, PageLayoutProperties, Style, TextProperties, ParagraphProperties from odf.text import P, PageNumber, A, Span

textdoc = OpenDocumentText() pl = PageLayout(name="pagelayout") pl.addElement(PageLayoutProperties(pagewidth='11in', pageheight='8.5in', printorientation="landscape", margintop='1in', marginleft='1in', marginbottom='0.5in', marginright='1in', numformat='1', writingmode='lr-tb')) textdoc.automaticstyles.addElement(pl) mp = MasterPage(name="Standard", pagelayoutname=pl) textdoc.masterstyles.addElement(mp)

hyperlinkStyle = Style(name="Hyperlink", parentstylename="Standard", family="text") hyperlinkStyle.addElement(TextProperties( attributes={"color": "#0000FF", "textunderlinetype": "single", "textunderlinestyle": "solid", "textunderlinewidth": "auto"}))

textdoc.styles.addElement(hyperlinkStyle)

plainStyle = Style(name="plainStyle", parentstylename="Standard", family="paragraph") plainStyle.addElement(ParagraphProperties(lineheight="130%")) textdoc.styles.addElement(plainStyle)

centerStyle = Style(name="centerStyle", parentstylename="Standard", family="paragraph") centerStyle.addElement(ParagraphProperties(textalign="center")) textdoc.styles.addElement(centerStyle)

f = Footer() fp = P() fp.addElement(PageNumber(text="1")) f.addElement(fp) mp.addElement(f)

h = Header() hp = P(text="Training name", stylename=centerStyle) h.addElement(hp) mp.addElement(h)

textdoc.text.addElement(P(text="Test text goes here", stylename=plainStyle))

sp = Span(text="hyperlink", stylename=hyperlinkStyle) a = A(href="https://www.cnn.com") a.addElement(sp) newP = P() newP.addElement(a) textdoc.text.addElement(newP)

textdoc.save("headers.odt")

Clone this wiki locally