Exemple #1
0
from odfdo import Document, Header

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

title1 = Header(1, "The Title")
body.append(title1)
my_document = Document('text')
# Now document is an empty text document issued from a template. It’s a
# bit like creating a new text document in your office application,
# except odfdo templates don’t create a default paragraph.

# 2 - Adding Content
# Contents go into the body
body = my_document.body
# Now we have a context to attach new elements to. In a text document, we
# generally want to write paragraphs, lists, headings, and a table of
# content to show the document hierarchy at first.

# 2.1 - Adding Main Title
# Titles are organised by level, starting from level 1.
#So let’s add the main title of our document:
title1 = Header(1, txt_1)
body.append(title1)

# 2.2 - Adding more Titles and Paragraphs
# title of second level:
title = Header(2, txt_a1)
body.append(title)

# Adding a basic Paragraph of plain text
paragraph = Paragraph(txt_a2)
body.append(paragraph)

# title of second level:
title = Header(2, txt_b1)
body.append(title)
Exemple #3
0
    orig = complex((17 - side) / 2.0, vpos)
    v1 = Vector(orig, orig + complex(side, 0))
    v2 = Vector(v1.b, orig + cmath.rect(side, cmath.pi / 3))
    v3 = Vector(v2.b, orig)
    center = (v1.a + v1.b + v2.b) / 3
    vlist = koch([v1, v2, v3], cycle=CYCLES)
    return center, vlist


if __name__ == "__main__":

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

    print("Making some Koch fractal")
    title = Header(1, "Some Koch fractal")
    body.append(title)

    style = document.get_style("graphic")
    style.set_properties({"svg:stroke_color": "#0000ff"})
    style.set_properties(fill_color="#ffffcc")

    para = Paragraph("")
    body.append(para)

    # some computation of oordinates
    center, vlist = make_coords(side=12.0, vpos=8.0)

    # create a circle
    rad = 8.0
    pos = center - complex(rad, rad)
Exemple #4
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().
    uri = "http://enneagon.org/phrases/%s" % sentences
    try:
        text = urllib.request.urlopen(uri).read().decode("iso8859-1")
    except:
        text = "Almost no text."
    return text


from odfdo import Document, Header, Paragraph

# Create the document
my_document = Document("text")
body = my_document.body

# Add content (See Create_a_basic_document.py)
title1 = Header(1, random_text(1)[:70])
body.append(title1)
for p in range(3):
    title = Header(2, random_text(1)[:70])
    body.append(title)
    paragraph = Paragraph(random_text(10))

    # Adding Footnote
    # Now we add a footnote on each paragraph
    # Notes are quite complex so they deserve a dedicated API on paragraphs:
    some_word = paragraph.text_recursive.split()[3]
    # choosing the 4th word of the paragraph to insert the note
    paragraph.insert_note(
        after=some_word,  # The word after what the “¹” citation is inserted.
        note_id=f"note{p}",  # The unique identifier of the note in the document.
        citation="1",  # The symbol the user sees to follow the footnote.
Exemple #6
0
from odfdo import Document, Frame, Header, DrawImage, Paragraph, Cell, Row
from odfdo import Table, Column, FIRST_CHILD

# Hello messages
print('odfdo installation test')
print(' Version           : %s' % __version__)
print()
print('Generating test_output/use_case1.odt ...')

# Go
document = Document('text')
body = document.body

for numero, filename in enumerate(listdir('samples')):
    # Heading
    heading = Header(1, text=filename)
    body.append(heading)
    path = join('samples', filename)
    mimetype, _ = guess_type(path)
    if mimetype is None:
        mimetype = 'application/octet-stream'
    if mimetype.startswith('image/'):
        # Add the image
        internal_name = 'Pictures/' + filename
        image = Image.open(path)
        width, height = image.size
        paragraph = Paragraph('Standard')
        # 72 ppp
        frame = Frame('frame_%d' % numero, 'Graphics',
                      str(int(width / 72.0)) + 'in',
                      str(int(height / 72.0)) + 'in')
Exemple #7
0
from odfdo import Document, Header, Paragraph, Table

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

# Let's add another section to make our document clear:

body.append(Header(1, "Tables"))
body.append(Paragraph("A 3x3 table:"))

# Creating a table :

table = Table("Table 1", width=3, height=3)
body.append(table)
Exemple #8
0
# ------------
path = join("samples", "image.png")
image = Image.open(path)
width, height = image.size
# Add the image
image_uri = document.add_file(path)
draw_size = (f"{width/100:.2f}cm", f"{height/100:.2f}cm")
image_frame = Frame.image_frame(image_uri, size=draw_size, position=("0cm", "0cm"))
paragraph = Paragraph("", style="Standard")
paragraph.append(image_frame)
body.append(paragraph)
body.append(Paragraph())

# 1- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = Header(1, text="Congratulations !")
body.append(heading)

# The style
style = Style(
    "paragraph",
    "style1",
    parent="Standard",
    area="text",
    color=rgb2hex("blue"),
    background_color=rgb2hex("red"),
)
document.insert_style(style)

# The paragraph
text = "This document has been generated by the odfdo installation test."
Exemple #9
0
              str(int(height / 72.0)) + 'in')
internal_name = 'Pictures/image.png'
image = DrawImage(internal_name)
frame.append(image)
paragraph.append(frame)
body.append(paragraph)

# And store the data
container = document.container
with open('samples/image.png', 'rb') as f:
    content = f.read()
container.set_part(internal_name, content)

# 1- Congratulations (=> style on paragraph)
# ------------------------------------------
heading = Header(1, text='Congratulations !')
body.append(heading)

# The style
style = Style('paragraph',
              "style1",
              parent="Standard",
              area='text',
              color=rgb2hex('blue'),
              background_color=rgb2hex('red'))
document.insert_style(style)

# The paragraph
text = 'This document has been generated by the odfdo installation test.'
paragraph = Paragraph(text, style="style1")
body.append(paragraph)
Exemple #10
0
    cat_list = []
    price = 10.0
    for p in range(5):
        cat_list.append(Product(chr(65 + p), price))
        price += 10.5
    return cat_list


tax_rate = .196

if __name__ == "__main__":
    commercial = Document('text')
    body = commercial.body
    catalog = make_catalog()

    title1 = Header(1, "Basic commercial document")
    body.append(title1)
    title11 = Header(2, "Available products")
    body.append(title11)
    paragraph = Paragraph("Here the list:")
    body.append(paragraph)

    # List of products in a list :
    product_list = List()
    body.append(product_list)
    for product in catalog:
        item = ListItem("%-10s, price: %.2f €" % (product.name, product.price))
        product_list.append(item)

    title12 = Header(2, "Your command")
    body.append(title12)