file_name = source[0]

    presentation = Document(file_name)
    presentation_body = presentation.body

    uri = presentation.add_file(options.image)

    width, height = make_image_size(options.image, float(options.size))

    # Create a frame for the image
    image_frame = Frame(
        url=uri,
        name=file_name,
        text='',  # Text over the image object
        size=(width, height),  # Display size of image
        anchor_type='page',
        page_number=None,
        position=(pos_x, pos_y),
        style=None)
    image_frame.svg_title = title
    image_frame.svg_description = text

    # Append all the component
    i = start
    while True:
        slide = presentation_body.get_draw_page(position=i)
        # Create a frame for the image
        image_frame = Frame(
            url=uri,
            name=file_name,
Esempio n. 2
0
    # Presentation got a body in which content is stored
    presentation_body = presentation.body

    # For each image, we create a page in the presentation and display the image
    # and some text on this frame
    for image in images_pool:
        # add the file to the document
        uri = presentation.add_file(image.path)

        # Create an underlying page for the image and the text
        page = DrawPage("Page " + image.name)

        # Create a frame for the image
        image_frame = Frame.image_frame(
            image=uri,
            name=image.name,
            text="",  # Text over the image object
            size=(image.disp_w, image.disp_h),  # Display size of image
            anchor_type="page",
            page_number=None,
            position=(image.pos_x, image.pos_y),
            style=None,
        )

        # Append all the component
        page.append(image_frame)
        presentation_body.append(page)

    # Finally save the result
    presentation.save(target=output_file, pretty=True)
# I want to write "Hello World" in the middle of the first page.

from odfdo import Document, Frame, DrawPage

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

page = DrawPage("page1", name="Page 1")
body.append(page)
text_frame = Frame(
    ["Hello", "World"],
    size=("7cm", "5cm"),
    position=("11cm", "8cm"),
    style="colored",
    text_style="big",
)
Esempio n. 4
0
# I want to write "Hello World" in the middle of the first page.

from odfdo import Document, Frame, DrawPage

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

page = DrawPage('page1', name="Page 1")
body.append(page)
text_frame = Frame(["Hello", "World"],
                   size=('7cm', '5cm'),
                   position=('11cm', '8cm'),
                   style="colored",
                   text_style="big")
    max_border = 16.0  # max size of the greatest border, in cm
    a = max_border * ratio
    b = max_border
    if ratio > 1.0:
        a /= ratio
        b /= ratio

    # Create an underlying page for the image and the text
    page = DrawPage("page " + name)

    # Create a frame for the image
    image_frame = Frame.image_frame(
        image=uri,
        text="",  # Text over the image object
        size=("%scm" % a, "%scm" % b),  # Display size of image
        anchor_type="page",
        page_number=None,
        position=("3.5cm", "3.5 cm"),
        style=None,
    )

    # Add some text object somehere on the frame, with a text frame
    legend = "Image %s from Wikipedia document / %s" % (name, filename)
    text_frame = Frame.text_frame(
        legend,
        size=("26cm", "2cm"),
        position=("0.5cm", "0.5cm"),
        style="Standard",
        text_style="Standard",
    )
Esempio n. 6
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)
Esempio n. 7
0
    # 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')
        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:
Esempio n. 8
0
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
        image_uri = document.add_file(path)
        # compute size
        image = Image.open(path)
        width, height = image.size
        draw_size = (f"{width/400:.2f}in", f"{height/400:.2f}in")
        image_frame = Frame.image_frame(image_uri, size=draw_size, anchor_type="char")
        paragraph = Paragraph("")
        paragraph.append(image_frame)
        body.append(paragraph)
        body.append(Paragraph(""))
    elif mimetype in ("text/csv", "text/comma-separated-values"):
        table = Table(f"table {numero}", style="Standard")
        csv = reader(open(path))
        for line in csv:
            size = len(line)
            row = Row()
            for value in line:
                cell = Cell(value)
                row.append_cell(cell)
            table.append_row(row)
        for i in range(size):
Esempio n. 9
0
print()
print("Generating test_output/use_case2.odt ...")

# 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",
def main():
    usage = 'usage: %prog -i IMAGE -r RANGE -s SIZE PRESENTATION'
    description = 'Add an image on some pages of a presentation.'
    parser = OptionParser(usage, description=description)
    parser.add_option('-i',
                      '--image',
                      dest='image',
                      help='Image to be added',
                      action='store',
                      type='string')
    parser.add_option('-r',
                      '--range',
                      dest='range',
                      help='Range of the slides',
                      action='store',
                      type='string')
    parser.add_option('-s',
                      '--size',
                      dest='size',
                      help='max width in cm of the image',
                      action='store',
                      type='float')

    options, source = parser.parse_args()
    if not source or not options.image or not options.range or not options.size:
        print('need options !')
        parser.print_help()
        exit(0)

    lst = options.range.split('-')
    start = int(lst[0]) - 1
    end = int(lst[1])
    file_name = source[0]
    image_size = make_image_size(options.image, float(options.size))

    presentation = Document(file_name)
    presentation_body = presentation.body

    uri = presentation.add_file(options.image)

    # Append all the component
    for i in range(start, end):
        # Create a frame for the image
        image_frame = Frame.image_frame(
            image=uri,
            text='',  # Text over the image object
            size=image_size,  # Display size of image
            anchor_type='page',
            page_number=None,
            position=image_position,
            style=None)
        image_frame.svg_title = title
        image_frame.svg_description = text
        slide = presentation_body.get_draw_page(position=i)
        slide.append(image_frame)

    # Finally save the result
    name_parts = file_name.split('.')
    name_parts.insert(-1, modified_file_suffix)
    new_name = '.'.join(name_parts)

    presentation.save(new_name)
Esempio n. 11
0
count = 0

for blurb in lst:
    count += 1
    text = blurb
    name = "%s - %s" % (count, text[:10])
    page = DrawPage(name)
    # choosing some style:
    size = 48
    for i, max_size in enumerate(text_sz):
        if len(text) > max_size:
            size = variants[i]
            break

    text_frame = Frame.text_frame(
        text,
        size=('24cm', '2cm'),
        position=('2cm', '8cm'),
        style='Gloup%s' % size,
        text_style='Gloup%s' % size)

    page.append(text_frame)
    presentation_body.append(page)

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

output = os.path.join('test_output', output_filename)

presentation.save(target=output, pretty=True)
    ratio = embedded_image_ratio(uri, part)
    max_border = 16.0  # max size of the greatest border, in cm
    a = max_border * ratio
    b = max_border
    if ratio > 1.0:
        a /= ratio
        b /= ratio

    # Create an underlying page for the image and the text
    page = DrawPage("page " + name)

    # Create a frame for the image
    image_frame = Frame.image_frame(
        image=uri,
        text="",  # Text over the image object
        size=("%scm" % a, "%scm" % b),  # Display size of image
        anchor_type='page',
        page_number=None,
        position=('3.5cm', '3.5 cm'),
        style=None)

    # Add some text object somehere on the frame, with a text frame
    legend = "Image %s from Wikipedia document / %s" % (name, filename)
    text_frame = Frame.text_frame(
        legend,
        size=('26cm', '2cm'),
        position=('0.5cm', '0.5cm'),
        style="Standard",
        text_style="Standard")

    # Append all the component, do not forget to add the actuel image file
    # into the Picture global directory of the presentation file with set_part
Esempio n. 13
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)
Esempio n. 14
0
for blurb in lst:
    count += 1
    text = blurb
    name = "%s - %s" % (count, text[:10])
    page = DrawPage(name)
    # choosing some style:
    size = 48
    for i, max_size in enumerate(text_sz):
        if len(text) > max_size:
            size = variants[i]
            break

    text_frame = Frame.text_frame(
        text,
        size=("24cm", "2cm"),
        position=("2cm", "8cm"),
        style="Gloup%s" % size,
        text_style="Gloup%s" % size,
    )

    page.append(text_frame)
    presentation_body.append(page)

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

output = os.path.join("test_output", output_filename)

presentation.save(target=output, pretty=True)
Esempio n. 15
0
def main():
    usage = "usage: %prog -i IMAGE -r RANGE -s SIZE PRESENTATION"
    description = "Add an image on some pages of a presentation."
    parser = OptionParser(usage, description=description)
    parser.add_option(
        "-i",
        "--image",
        dest="image",
        help="Image to be added",
        action="store",
        type="string",
    )
    parser.add_option(
        "-r",
        "--range",
        dest="range",
        help="Range of the slides",
        action="store",
        type="string",
    )
    parser.add_option(
        "-s",
        "--size",
        dest="size",
        help="max width in cm of the image",
        action="store",
        type="float",
    )

    options, source = parser.parse_args()
    if not source or not options.image or not options.range or not options.size:
        print("need options !")
        parser.print_help()
        exit(0)

    lst = options.range.split("-")
    start = int(lst[0]) - 1
    end = int(lst[1])
    file_name = source[0]
    image_size = make_image_size(options.image, float(options.size))

    presentation = Document(file_name)
    presentation_body = presentation.body

    uri = presentation.add_file(options.image)

    # Append all the component
    for i in range(start, end):
        # Create a frame for the image
        image_frame = Frame.image_frame(
            image=uri,
            text="",  # Text over the image object
            size=image_size,  # Display size of image
            anchor_type="page",
            page_number=None,
            position=image_position,
            style=None,
        )
        image_frame.svg_title = title
        image_frame.svg_description = text
        slide = presentation_body.get_draw_page(position=i)
        slide.append(image_frame)

    # Finally save the result
    name_parts = file_name.split(".")
    name_parts.insert(-1, modified_file_suffix)
    new_name = ".".join(name_parts)

    presentation.save(new_name)
Esempio n. 16
0
print('Generating test_output/use_case2.odt ...')

# 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",