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]) - 1 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
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)
print("no image found !") parser.print_help() exit(0) # Creation of the output Presentation document : # presentation = Document_from_type('presentation') # 092 presentation = Document("presentation") # 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, )
print("odfdo installation test") print(f"version : {__version__}") 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",
exit(0) if not options.new_img: print("Need some new picture !") parser.print_help() exit(0) if not sources: print("Need some ODF source !") parser.print_help() exit(0) t0 = time.time() with open(options.old_img, "rb") as f: old_content_footprint = make_footprint(f.read()) # making the new image content : buffer = Document("text") url = buffer.add_file(options.new_img) new_content = buffer.get_part(url) for source in sources: if os.path.isdir(source): for root, dirs, files in os.walk(source): for name in files: replace_odf_pics( os.path.join(root, name), old_content_footprint, new_content ) else: replace_odf_pics(source, old_content_footprint, new_content) elapsed = int(time.time() - t0) print( "%s images updated from %s images in %s ODF files in %s sec." % (counter_hit, counter_image, counter_odf, elapsed)
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)
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)
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)