Examples#

# create the input pptx
item = server.create_item(name="input.pptx", source="pptx-test", sequence=0)
item.set_payload_file(os.path.join(test_dir, "test_data", "input.pptx"))
if server.put_objects(item) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push source pptx object")

# source pptx item
item = server.create_item(name="input.pptx", source="pptx-test", sequence=0)
item.set_payload_file(os.path.join(test_dir, "test_data", "input.pptx"))
if server.put_objects(item) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push source pptx object")

# title
title = server.create_item(name="title_text", source="pptx-test", sequence=0)
title.set_payload_string("My presentation")
if server.put_objects([title]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push title object")


text = server.create_item(name="text", source="pptx-test", sequence=0)
text.set_payload_string(
    "On a dark desert highway, cool wind in my hair..."
    "\nWarm smell of colitas, rising up through the air..."
    "\nUp ahead in the distance, I saw shimmering light..."
    "\nMy head grew heavy and my sight grew dim..."
    "\nI had to stop for the night..."
)
if server.put_objects([text]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push text object")

# html_title item
html_title = server.create_item(name="html_title", source="pptx-test", sequence=0)
html_title.set_payload_string("My HTML item")
if server.put_objects([html_title]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push html_title object")

# HTML item
html = server.create_item(name="html", source="pptx-test", sequence=0)
html.set_payload_html(
    "<h1>Heading 1</h1>"
    "<h2>Heading 2</h2>"
    "<h3>Heading 3</h3>"
    "<h4>Heading 4</h4>"
    "<h5>Heading 5</h5>"
    "Two breaks below"
    "<br><br />"
    "<h6>Heading 6 (& one break below)</h6>"
    "<br>"
    "The end"
)
html.add_tag("pptx_slide_title", "headers and breaks")
if server.put_objects([html]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push text object")

# HTML item for insertion into slide title
html = server.create_item(name="html-anim-title", source="pptx-test", sequence=0)
html.set_payload_html("<h1>Anim + text</h1>Takes up two slides")
html.add_tag("pptx_slide_title", "--movie")
if server.put_objects([html]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push text object")

# Image item
image_title = server.create_item(name="image_title", source="pptx-test", sequence=0)
image_title.set_payload_string("My image")
if server.put_objects([image_title]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push image_title object")
with open(os.path.join(test_dir, "test_data", "image.png"), "rb") as fp:
    img = fp.read()

image_item = server.create_item(name="image", source="pptx-test", sequence=0)
image_item.set_payload_image(img)
if server.put_objects([image_item]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push image_item object")

# movie item
anim_title = server.create_item(name="anim_title", source="pptx-test", sequence=0)
anim_title.set_payload_string("My movie with text")
if server.put_objects([anim_title]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push anim_title object")

anim = server.create_item(name="anim", source="pptx-test", sequence=0)
anim.set_payload_animation(os.path.join(test_dir, "test_data", "movie.mp4"))
if server.put_objects([anim]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push anim object")

# end text
end_text = server.create_item(name="end_text", source="pptx-test", sequence=0)
end_text.set_payload_string("The end")
if server.put_objects([end_text]) != requests.codes.ok:
    print(server.get_last_error())
    print("Error: Unable to push end_text object")

### USING ALL SLIDES ###
pptx_template = server.create_template(
    name="pptx", parent=None, report_type="Layout:pptx"
)
# set the input pptx file
pptx_template.input_pptx = "input.pptx"
# set the output pptx file
pptx_template.output_pptx = "output-get.pptx"
# use_all_slides will use all the slides from the input pptx
pptx_template.use_all_slides = "1"
# set a top level filter of items in the database.
pptx_template.set_filter("A|i_src|cont|pptx-test;")
# save
server.put_objects(pptx_template)

 # final export
try:
    server.get_pptx_from_report(
        pptx_template.guid, directory_name=db_dir, query=None
    )
except Exception as e:
    print(f"Error: unable to save the pptx report: {e}")
verify_export(os.path.join(db_dir, pptx_template.output_pptx))

# export the same report again with the specific REST API
# uses a file name different from the one specified in output_pptx
out_path = os.path.join(db_dir, "output.pptx")
try:
    server.export_report_as_pptx(
        pptx_template.guid,
        out_path,
        query=None,
    )
except Exception as e:
    print(f"Error: unable to save the pptx report using the REST API: {e}")

### USING SPECIFIC SLIDES ###
pptx_template = server.create_template(
    name="pptx-select", parent=None, report_type="Layout:pptx"
)
# set the input pptx file
pptx_template.input_pptx = "input.pptx"
# set the output pptx file
pptx_template.output_pptx = "output-select.pptx"
# set a top level filter of items in the database.
pptx_template.set_filter("A|i_src|cont|pptx-test;")
# stop using all slides
pptx_template.use_all_slides = "0"
server.put_objects(pptx_template)

# start slide
slide = server.create_template(
    name="start", parent=pptx_template, report_type="Layout:pptxslide"
)
# intentionally avoid source_slide here
server.put_objects(slide)
server.put_objects(pptx_template)

# toc
slide = server.create_template(
    name="toc", parent=pptx_template, report_type="Layout:pptxslide"
)
slide.source_slide = "2"
server.put_objects(slide)
server.put_objects(pptx_template)

slide = server.create_template(
    name="html", parent=pptx_template, report_type="Layout:pptxslide"
)
slide.source_slide = "3"
server.put_objects(slide)
server.put_objects(pptx_template)

slide = server.create_template(
    name="anim-text", parent=pptx_template, report_type="Layout:pptxslide"
)
slide.source_slide = "5"
slide.set_html("<h1>Anim + text</h1>Takes up two slides")
slide.set_filter("O|i_name|cont|anim;O|i_name|cont|text;")
server.put_objects(slide)
server.put_objects(pptx_template)

# end
slide = server.create_template(
    name="end", parent=pptx_template, report_type="Layout:pptxslide"
)
slide.source_slide = "18"
server.put_objects(slide)
server.put_objects(pptx_template)

# final export
out_path = os.path.join(db_dir, pptx_template.output_pptx)
    try:
    server.export_report_as_pptx(
        pptx_template.guid,
        out_path,
        query=None,
    )
except Exception as e:
    print(f"Error: unable to save the pptx report using the REST API: {e}")