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." paragraph = Paragraph(text, style="style1") body.append(paragraph) # 2- Your environment (=> a table) # -------------------------------- heading = Header(1, text="Your environment") body.append(heading)
color='white', ) style = create_table_cell_style( color='grey', background_color=cell_value, border_right=border_rl, border_left=border_rl, border_bottom=border_bt, border_top=border_bt, ) name = document.insert_style(style=style, automatic=True) cell = Cell(value=rgb2hex(cell_value), style=name) row.append_cell(cell) table.append_row(row) row_style = Style('table-row', height='1.80cm') name_style_row = document.insert_style(style=row_style, automatic=True) for row in table.get_rows(): row.style = name_style_row table.set_row(row.y, row) col_style = Style('table-column', width='3.6cm') name = document.insert_style(style=col_style, automatic=True) for column in table.get_columns(): column.style = col_style table.set_column(column.x, column) body.append(table) if not exists('test_output'): mkdir('test_output')
'style:family="paragraph" style:class="text">' '<style:paragraph-properties fo:margin="100%" ' 'fo:margin-left="0cm" ' 'fo:margin-right="0cm" fo:margin-top="0cm" ' 'fo:margin-bottom="0.15cm" ' 'style:contextual-spacing="false" fo:text-indent="0cm" ' 'style:auto-text-indent="false" fo:padding="0cm" ' 'fo:border-left="none" ' 'fo:border-right="none" fo:border-top="none" ' 'fo:border-bottom="0.06pt solid #000000"/>' '<style:text-properties style:font-name="Liberation Sans" ' 'fo:font-size="9pt"/>' "</style:style>")) # some odfdo generated style (for bold Span) _style_bold = Style("text", name="bolder", bold=True) # Some plain text : text_1 = ("Lorem ipsum dolor sit amet,\n\t" "consectetuer adipiscing elit.\n\tSed" "non risus.\n\tSuspendisse lectus tortor,\n" "ndignissim sit amet, \nadipiscing nec," "\nultricies sed, dolor.\n\n" " Cras elementum ultrices diam. Maecenas ligula massa," "varius a,semper congue, euismod non," " mi. Proin porttitor, orci nec nonummy" "molestie, enim est eleifend mi," " non fermentum diam nisl sit amet erat.") text_2 = ("Vestibulum " "ante "
# 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) # 2- Your environment (=> a table) # -------------------------------- heading = Header(1, text='Your environment') body.append(heading) data = []
color="white", ) style = create_table_cell_style( color="grey", background_color=cell_value, border_right=border_rl, border_left=border_rl, border_bottom=border_bt, border_top=border_bt, ) name = document.insert_style(style=style, automatic=True) cell = Cell(value=rgb2hex(cell_value), style=name) row.append_cell(cell) table.append_row(row) row_style = Style("table-row", height="1.80cm") name_style_row = document.insert_style(style=row_style, automatic=True) for row in table.get_rows(): row.style = name_style_row table.set_row(row.y, row) col_style = Style("table-column", width="3.6cm") name = document.insert_style(style=col_style, automatic=True) for column in table.get_columns(): column.style = col_style table.set_column(column.x, column) body.append(table) if not exists("test_output"): mkdir("test_output")
from odfdo import Document, Style document = Document("text") body = document.body # Let's imagine the sample_styles.odt document contains an interesting style. # # So let’s first fetch the style: try: odfdo_styles = Document("sample_styles.odt") highlight = odfdo_styles.get_style("text", display_name="Yellow Highlight") except OSError: # let's create some *very simple* text style. highlight = Style("text", display_name="Yellow Highlight", color="blue", italic=True) # We made some assumptions here: # # ‘text’ : The family of the style, text styles apply on # individual characters. # ”Yellow Highlight” : The name of the style as we see it in a desktop # application. # display_name : Styles have an internal name (“Yellow_20_Highlight” # in this example) but we gave the display_name # instead. # # We hopefully have a style object that we add to our own collection: document.insert_style(highlight, automatic=True)
output_filename = "my_generated_presentation.odp" presentation = Document('presentation') presentation_body = presentation.body # Creating a smooth style for the graphic item base_style = Style( 'graphic', name='Gloup48', parent="standard", stroke="none", fill_color="#b3b3b3", textarea_vertical_align="middle", padding_top="1cm", padding_bottom="1cm", padding_left="1cm", padding_right="1cm", line_distance="0cm", guide_overhang="0cm", guide_distance="0cm", ) base_style.set_properties(area='paragraph', align='center') base_style.set_properties( area='text', color="#dd0000", text_outline="false", font="Liberation Sans", font_family="Liberation Sans", # compatibility font_style_name="Bold",
'style:family="paragraph" style:class="text">' '<style:paragraph-properties fo:margin="100%" ' 'fo:margin-left="0cm" ' 'fo:margin-right="0cm" fo:margin-top="0cm" ' 'fo:margin-bottom="0.15cm" ' 'style:contextual-spacing="false" fo:text-indent="0cm" ' 'style:auto-text-indent="false" fo:padding="0cm" ' 'fo:border-left="none" ' 'fo:border-right="none" fo:border-top="none" ' 'fo:border-bottom="0.06pt solid #000000"/>' '<style:text-properties style:font-name="Liberation Sans" ' 'fo:font-size="9pt"/>' '</style:style>')) # some odfdo generated style (for bold Span) _style_bold = Style('text', name='bolder', bold=True) # Some plain text : text_1 = ('Lorem ipsum dolor sit amet,\n\t' 'consectetuer adipiscing elit.\n\tSed' 'non risus.\n\tSuspendisse lectus tortor,\n' 'ndignissim sit amet, \nadipiscing nec,' '\nultricies sed, dolor.\n\n' ' Cras elementum ultrices diam. Maecenas ligula massa,' 'varius a,semper congue, euismod non,' ' mi. Proin porttitor, orci nec nonummy' 'molestie, enim est eleifend mi,' ' non fermentum diam nisl sit amet erat.') text_2 = ('Vestibulum ' 'ante '
if __name__ == "__main__": try: source = sys.argv[1] except IndexError: source = get_default_doc() document = Document(source) body = document.body print("Add some span styles to", source) # create some random text styles for i in range(64): style = Style( 'text', name='rnd%s' % i, color=(randrange(256), randrange(256), randrange(256)), size="%s" % (8 + i / 5), ) document.insert_style(style) words = set(body.text_recursive.split()) for word in words: name = style_name() style = document.get_style('text', name) for paragraph in body.get_paragraphs() + body.get_headers(): # apply style to each text matching with the regex of some word paragraph.set_span(name, regex=word) if not os.path.exists('test_output'): os.mkdir('test_output')
if __name__ == "__main__": try: source = sys.argv[1] except IndexError: source = get_default_doc() document = Document(source) body = document.body print("Add some span styles to", source) # create some random text styles for i in range(64): style = Style( "text", name="rnd%s" % i, color=(randrange(256), randrange(256), randrange(256)), size="%s" % (8 + i / 5), ) document.insert_style(style) words = set(body.text_recursive.split()) for word in words: name = style_name() style = document.get_style("text", name) for paragraph in body.get_paragraphs() + body.get_headers(): # apply style to each text matching with the regex of some word paragraph.set_span(name, regex=word) if not os.path.exists("test_output"): os.mkdir("test_output")
from odfdo import Document, Style document = Document('text') body = document.body # Let's imagine the sample_styles.odt document contains an interesting style. # # So let’s first fetch the style: try: odfdo_styles = Document('sample_styles.odt') highlight = odfdo_styles.get_style('text', display_name="Yellow Highlight") except OSError: # let's create some *very simple* text style. highlight = Style('text', display_name="Yellow Highlight", color='blue', italic=True) # We made some assumptions here: # # ‘text’ : The family of the style, text styles apply on # individual characters. # ”Yellow Highlight” : The name of the style as we see it in a desktop # application. # display_name : Styles have an internal name (“Yellow_20_Highlight” # in this example) but we gave the display_name # instead. # # We hopefully have a style object that we add to our own collection: document.insert_style(highlight, automatic=True)