filename = "presentation_base.odp" presentation_base = Document(filename) output_filename = "my_extracted_slides.odp" if __name__ == "__main__": # extract = sys.argv[1:] extract = " 3 5 2 2" extracted = Document("presentation") body_base = presentation_base.body body_extracted = extracted.body # Important, copy styles too: extracted.delete_styles() extracted.merge_styles_from(presentation_base) for i in extract.split(): try: slide_position = int(i) - 1 slide = body_base.get_draw_page(position=slide_position) except: continue if slide is None: continue slide = slide.clone body_extracted.append(slide)
# ODF export of Wikipedia article Hitchhiker's Guide to the Galaxy (CC-By-SA) filename = "collection2.odt" style_filename = "lpod_styles.odt" # copied here from the odfdo package # We want to change the styles of the collection2.odt. # We know the odfdo_styles.odt document contains an interesting style. # So let’s first fetch the style: style_document = Document(style_filename) # Open our document: document = Document(filename) # We could change only some styles, but here we want a clean basis: document.delete_styles() # And now the actual style change: document.merge_styles_from(style_document) if not os.path.exists('test_output'): os.mkdir('test_output') # Saving the document (with a different name) document.save(target=os.path.join('test_output', "my_collection_styled.odt"), pretty=True) ################################################################################ # For more advanced version, see the odfdo-style.py script in scripts folder # ################################################################################
type="string", ) options, sources = parser.parse_args() if not sources: print("need presentations sources !") parser.print_help() sys.exit(0) if options.output: concat_filename = options.output else: concat_filename = default_concat_filename t0 = time.time() # prepare destination file concat_presentation = Document("presentation") concat_presentation.delete_styles() for source in sources: if os.path.isdir(source): for root, dirs, files in os.walk(source): for name in files: parse_odp(os.path.join(root, name), concat_presentation) else: parse_odp(source, concat_presentation) concat_presentation.save(target=concat_filename, pretty=True) elapsed = int(time.time() - t0) nb_slides = len(concat_presentation.body.get_draw_pages()) print("%s presentations concatenated in %s (%s slides) in %ss." % (counter_odp, concat_filename, nb_slides, elapsed))