Mastering PowerPoint Generation with Mendix: A Step-by-Step Guide

Indium is back with another intriguing use case that often leaves us wondering: how can we simplify PowerPoint generation? We frequently create presentations for various purposes, but have you ever considered automating this process with Mendix? Imagine being able to generate presentations directly from your Mendix applications. We’ll explore how to integrate Mendix with PowerPoint to streamline your reporting and presentation processes.

Let’s dive into the details to discover the process of creating a presentation using a Java action. Many enterprises need to generate PowerPoint presentations dynamically from business data (e.g., reports, analytics, or customer summaries). In this blog we will generate a simple presentation with data extracted from an image using AWS Textract. We will also cover formatting titles, paragraphs, and more.

Prerequisites

Before we dive into the steps, make sure you have:

A Mendix application with a basic domain model, as illustrated below:

Create a simple Mendix application using the domain model mentioned above. Additionally, ensure that the following POI JAR files are added to the user lib folder of your project, as shown below:

We will generate a simple presentation using the data extracted using the Amazon Textract Connector. In an upcoming blog, we will explain the extraction process using the Amazon Textract Connector. Let’s focus on generating the presentation using the data retrieved from the extraction process.

Extracting the text requires a few steps before generating the presentation. To facilitate this, I will create a page where users can upload an image containing the data to be extracted.

Step 1: Create an overview page where users can upload an image, as illustrated below.

Step 2: Allow users to upload the image and save it to the system.

Step 3: Provide a button to initiate the text extraction process, as shown. Once the process is complete, the extracted data from the image will be displayed, as seen below. Use the retrieved data to generate a presentation.

Step 4: To generate a presentation, create a Java action for this purpose. The action will take two parameters:

  • File: A Document object representing the file.
  • List of Objects: A list of AWSTextractResults objects containing the data extracted from the image.

This Java action will handle the process of generating a PowerPoint presentation. The action output will be a PowerPoint file represented as a Document object.

Discover how Mendix can help you automate and elevate your presentations.

Reach out to Indium!

Step 5: Click Deploy in Eclipse to edit the Java action. Remove the line containing the sentence, “Java action was not implemented”.

Step 6: Now, start writing the code between the begin user code and end user code sections.

Step 7: Create an XMLSlideShow object which helps to create the presentation file.

XMLSlideShow ppt = new XMLSlideShow();

XSLFSlideMaster slideMaster = ppt.getSlideMasters().get(0);

// Setting pagesize for the ppt

ppt.setPageSize(new java.awt.Dimension(750, 600));

Step 8: Add the following code to create the first slide with the presentation title and apply formatting to enhance its appearance.

XSLFSlideLayout titleLayout = slideMaster.getLayout(SlideLayout.TITLE);

XSLFSlide slide1 = ppt.createSlide(titleLayout);

XSLFTextShape title1 = slide1.getPlaceholder(0);

// Adding the title for the presentation

title1.setText(“AWS Textract Results”);

Step 9:  Use the following code to create the next slide with a new subtitle and include the data retrieved from the image

XSLFSlideLayout titlecontentLayout = slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);

// Added this loop to iterate over the results list and print the data in the PowerPoint presentation

while (Results.size() > 0) {

XSLFSlide newslide = ppt.createSlide(titlecontentLayout);

XSLFTextShape newtitle = newslide.getPlaceholder(0);

newtitle.setText(“Extracted Content from Image”);

XSLFTextShape body = newslide.getPlaceholder(1);

body.clearText();

for (int i = 0; i < Results.size(); i++) {

body.addNewTextParagraph().addNewTextRun()

.setText(Results.get(i).getKey() + ” : ” + Results.get(i).getValue());

Results.remove(i);

// Added this if block to terminate the for loop and prevent overlapping of data in the PowerPoint presentation.

if (i == 4) {

ppt.getSlides().add(newslide);

break;

}}}

Step 10: Finally, we reached the end of the code. Add the below piece of statementto complete the custom java action.

// Writing PPT Content to filedocument object

File file = new File(“AWSTextractResults.pptx”);

FileOutputStream out = new FileOutputStream(file);

ppt.write(out);

out.close();

InputStream targetStream = new FileInputStream(file);

Core.storeFileDocumentContent(getContext(), PPTFile.getMendixObject(), targetStream);

return __PPTFile;

The PowerPoint file will be generated quickly and should look like the example below.

To generate the presentation, I used the use case of extracting text from an image and adding the extracted data to the presentation. However, this approach can be applied to various use cases. For instance, you can pass any list of data to generate a PowerPoint presentation in a similar manner. Additionally, it is possible to create visual representations using the blocks or shapes provided by the presentation tools.

The extracted data from the image has been successfully added to the PowerPoint presentation as shown below,

Unlock Mendix Capabilities

As we wrap up, we’ve explored how to transform extracted data into a dynamic and engaging presentation, making information more accessible and actionable. But this is just the beginning! The journey of data extraction and automation has many exciting avenues to explore.

In our next blog, I’ll take you on a deep dive into the powerful Amazon Textract Connector, showcasing how you can seamlessly extract structured data from images and scanned documents. Whether you’re dealing with invoices, forms, or complex documents, this tool can revolutionize how you process and utilize information.



Author: Stella Davies
Stella D has over six years of experience in low-code software development and works at Indium Software as a Mendix Architect and Expert Mendix Developer. She has extensive experience in both Mendix application development and Java programming.