I have a PowerPoint template file which defines styles and layouts that I must to use to create a PowerPoint presentation. The content to use for the presentation is in HTML format. This is working relatively well with tags such as <strong>
and <u>
but I’m having some trouble with bulleted lists.
Given the following HTML list:
<ul>
<li>1</li>
<ul>
<li>1.1</li>
<li>1.2</li>
<ul>
<li>1.2.1</li>
</ul>
</ul>
<li>2</li>
<li>3</li>
<ul>
<li>3.1</li>
</ul>
</ul>
And using the ‘Title and Content’ layout from the template in the zip file at the end of the post, I would expect the result to be as follows:
expected-result.png (8.4 KB)
However the result is as follows:
actual-result.png (17.2 KB)
Two things in particular appear to be incorrect:
- The bullets are not the correct style. Look at the bullet style on the template – the first level should be a box, the second a diamond, and the third a tick.
- The bullets are one level indented further than they should be. This may not be obvious from the screenshot as the bullet styles are not correct but I’ve attached a zip file at the end of the post containing the generated PowerPoint file.
The code I am using to generate the PowerPoint is:
public void createExamplePpt(final String templateFile, final String saveLocation) throws FileNotFoundException {
License license = new License();
license.setLicense(getClass().getClassLoader().getResourceAsStream("Aspose.Total.Java.lic"));
FileInputStream fis = new FileInputStream(templateFile);
Presentation presentation = createPresentationFromTemplate(fis);
// Create a new slide using the 'Title and Content' layout
final ILayoutSlide layoutSlide = presentation.getMasters().get_Item(1).getLayoutSlides().get_Item(1);
final ISlide newSlide = presentation.getSlides().addEmptySlide(layoutSlide);
final String bodyPlaceholderText = "Click to edit body text";
final String html = "<ul>"
+ " <li>1</li>"
+ " <ul>"
+ " <li>1.1</li>"
+ " <li>1.2</li>"
+ " <ul>"
+ " <li>1.2.1</li>"
+ " </ul>"
+ " </ul>"
+ " <li>2</li>"
+ " <li>3</li>"
+ " <ul>"
+ " <li>3.1</li>"
+ " </ul>"
+ "</ul>";
// Find the placeholder on the new slide for the "body" text and replace it with the HTML content
for (IShape shape : newSlide.getShapes()) {
if (shape.getPlaceholder() != null) {
final IAutoShape placeHolderShape = (IAutoShape)shape;
final String placeholderText = placeHolderShape.getTextFrame().getText();
if (placeholderText.startsWith(bodyPlaceholderText)) {
final IParagraphCollection paragraphs = placeHolderShape.getTextFrame().getParagraphs();
paragraphs.addFromHtml(html);
paragraphs.removeAt(0);
}
}
}
presentation.save(saveLocation, SaveFormat.Pptx);
}
private Presentation createPresentationFromTemplate(final InputStream templateStream) {
Presentation template = new Presentation(templateStream);
Presentation presentation = new Presentation();
final Dimension2D templateSize = template.getSlideSize().getSize();
presentation.getSlideSize().setSize((float)templateSize.getWidth(), (float)templateSize.getHeight(), SlideSizeScaleType.DoNotScale);
presentation.getMasters().addClone(template.getMasters().get_Item(0));
return presentation;
}
powerpoint-from-html.zip (157.9 KB)
Is there a way to achieve what I want to do?