Beispiel #1
0
# Let's add another section to make our document clear:
# Annotations are notes that don’t appear in the document but typically on a
# side bar in a desktop application. So they are not printed.
from odfdo import Document, Paragraph, Header

document = Document("text")
body = document.body

body.append(Header(1, "Annotations"))
paragraph = Paragraph("A paragraph with an annotation in the middle.")
body.append(paragraph)

# Annotations are inserted like notes but they are simpler:

paragraph.insert_annotation(after="annotation",
                            body="It's so easy!",
                            creator="Luis")

# Annotation arguments are quite different:
# after   =>  The word after what the annotation is inserted.
# body    =>  The annotation itself, at the end of the page.
# creator =>  The author of the annotation.
# date    =>  A datetime value, by default datetime.now().
body.append(title1)
for p in range(3):
    title = Header(2, random_text(1)[:70])
    body.append(title)
    paragraph = Paragraph(random_text(10))

    # Adding Annotation
    # Annotations are notes that don’t appear in the document but
    # typically on a side bar in a desktop application. So they are not printed.

    # Now we add some annotation on each paragraph
    some_word = paragraph.text_recursive.split()[3]
    # choosing the 4th word of the paragraph to insert the note

    paragraph.insert_annotation(
        after=some_word,  # The word after what the annotation is inserted.
        body="It's so easy!",  # The annotation itself, at the end of the page.
        creator="Bob"  # The author of the annotation.
        # date= xxx              A datetime value, by default datetime.now().
    )

    body.append(paragraph)

if not os.path.exists('test_output'):
    os.mkdir('test_output')

output = os.path.join('test_output', 'my_document_with_annotations.odt')

# And finally save the document.
my_document.save(target=output, pretty=True)