org.pptx4j.samples.XHTMLFileToSlide Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j-ImportXHTML-samples Show documentation
Show all versions of docx4j-ImportXHTML-samples Show documentation
docx4j-ImportXHTML converts XHTML to OpenXML WordML (docx) using docx4j
The newest version!
package org.pptx4j.samples;
import java.io.File;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.docx4j.openpackaging.packages.PresentationMLPackage;
import org.docx4j.openpackaging.parts.PartName;
import org.docx4j.openpackaging.parts.PresentationML.MainPresentationPart;
import org.docx4j.openpackaging.parts.PresentationML.SlideLayoutPart;
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
import org.pptx4j.convert.in.xhtml.XHTMLtoPPTX;
public class XHTMLFileToSlide {
public static void main(String[] args) throws Exception {
// Where will we save our new .ppxt?
String outputfilepath = System.getProperty("user.dir") + "/OUT_XHTMLFileToSlide.pptx";
String inputfilepath = System.getProperty("user.dir") + "/fragment.html";
String baseUrl = "file:///C:/Users/jharrop/git/docx4j-ImportXHTML/";
String TXBODY_SHAPE_TEMPLATE =
"" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" ";
String stringFromFile = FileUtils.readFileToString(new File(inputfilepath), "UTF-8");
String content = stringFromFile;
// Setup target pptx
PresentationMLPackage presentationMLPackage = getPkg();
SlidePart slidePart =(SlidePart) presentationMLPackage.getParts().get(new PartName("/ppt/slides/slide1.xml"));
// TODO - add a convenience method to get slide by slide number!
// Process XHTML
XHTMLtoPPTX converter = new XHTMLtoPPTX(presentationMLPackage, slidePart, content, baseUrl);
converter.setTxBodyShapeTemplate(TXBODY_SHAPE_TEMPLATE);
List