コード例 #1
0
ファイル: create_a_basic_drawing.py プロジェクト: jdum/odfdo
    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)
    circle = EllipseShape(
        size=("%.2fcm" % (rad * 2), "%.2fcm" % (rad * 2)),
        position=("%.2fcm" % pos.real, "%.2fcm" % pos.imag),
    )
    para.append(circle)

    # create a drawing with a lot of lines
    para.append("number of lines: %s" % len(vlist))
    for v in vlist:
        line = LineShape(p1=v.in_cm(0), p2=v.in_cm(1))
        para.append(line)

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

output = os.path.join("test_output", "my_Koch_fractal.odt")

document.save(target=output, pretty=True)
コード例 #2
0
    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)
    circle = EllipseShape(size=('%.2fcm' % (rad * 2), '%.2fcm' % (rad * 2)),
                          position=('%.2fcm' % pos.real, '%.2fcm' % pos.imag))
    para.append(circle)

    # create a drawing with a lot of lines
    para.append('number of lines: %s' % len(vlist))
    for v in vlist:
        line = LineShape(p1=v.in_cm(0), p2=v.in_cm(1))
        para.append(line)

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

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

document.save(target=output, pretty=True)
コード例 #3
0
from odfdo import Document, Paragraph, Frame

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

uri = doc.add_file("newlogo.png")
image_frame = Frame.image_frame(uri,
                                size=("6cm", "4cm"),
                                position=("5cm", "10cm"))

# put image frame in a paragraph:
para = Paragraph("")
para.append(image_frame)
body.append(para)

# doc.save(target='test_picture.odt', pretty=True)
コード例 #4
0
ファイル: use_case1.py プロジェクト: thorstenb/odfdo
    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')
        image = DrawImage(internal_name)
        frame.append(image)
        paragraph.append(frame)
        body.append(paragraph)

        # And store the data
        container = document.container
        with open(path, 'rb') as f:
            content = f.read()
        container.set_part(internal_name, content)
    elif mimetype in ('text/csv', 'text/comma-separated-values'):
        table = Table("table %d" % numero, style="Standard")
        csv = reader(open(path))
        for line in csv:
            size = len(line)
            row = Row()
            for value in line:
                cell = Cell(value)
コード例 #5
0
ファイル: use_case2.py プロジェクト: jdum/odfdo
# Go
document = Document("text")
body = document.body

# 0- The image
# ------------
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"),