if is, how can I do that? any examples?thanks
@woshiwuqida,
Thank you for contacting support.
We have opened the following new ticket(s) in our internal issue tracking system and will consider your question according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39386
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@woshiwuqida,
Please try using the following code example:
public void main() {
Presentation presentation = new Presentation(presPath);
HtmlOptions htmlOptions = new HtmlOptions(new LinkController(resourcesOutputPath));
htmlOptions.setSlideImageFormat(SlideImageFormat.svg(new SVGOptions()));
// This line is needed to remove the slide title display in HTML.
// Comment it out if your prefer slide title displayed.
htmlOptions.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
System.out.println("Starting export");
presentation.save("output.html", SaveFormat.Html, htmlOptions);
}
class LinkController implements ILinkEmbedController
{
/// <summary>
/// Default parameterless constructor
/// </summary>
public LinkController()
{
m_externalImages = new HashMap<>();
s_templates.put("image/jpeg", "image-%d.jpg");
s_templates.put("image/png", "image-%d.png");
}
/// <summary>
/// Creates a class instance and sets the path where generated resource files will be saved to.
/// </summary>
/// <param name="savePath">Path to the location where generated resource files will be stored.</param>
public LinkController(String savePath)
{
this();
setSavePath(savePath);
}
public int getObjectStoringLocation(int id, byte[] entityData, String semanticName,
String contentType,
String recomendedExtension)
{
// Here we make the decision about storing images externally.
// The id is unique identifier of each object during the whole export operation.
String template;
// The s_templates dictionary contains content types we are going to store externally and the corresponding file name template.
if (s_templates.containsKey(contentType))
{
template = s_templates.get(contentType);
// Storing this resource to the export list
m_externalImages.put(id, template);
return LinkEmbedDecision.Link;
}
// All other resources, if any, will be embedded
return LinkEmbedDecision.Embed;
}
public String getUrl(int id, int referrer)
{
// Here we construct the resource reference string to form the tag: <img src="%result%">
// We need to check the dictionary to filter out unnecessary resources.
// Along with checking we extract the corresponding file name template.
String template;
if (m_externalImages.containsKey(id))
{
template = m_externalImages.get(id);
// Assuming we are going to store resource files just near the HTML file.
// The image tag will look like <img src="image-1.png"> with the appropriate resource Id and extension.
String fileUrl = String.format(template, id);
return fileUrl;
}
// null must be returned for the resources remaining embedded
return null;
}
public void saveExternal(int id, byte[] entityData)
{
// Here we actually save the resource files to disk.
// Once again, checking the dictionary. If the id is not found here it is a sign of an error in GetObjectStoringLocation or GetUrl methods.
if (m_externalImages.containsKey(id))
{
// Now we use the file name stored in the dictionary and combine it with a path as required.
// Constructing the file name using the stored template and the Id.
String fileName = String.format(m_externalImages.get(id), id);
// Combining with the location directory
String filePath = (getSavePath() == null ? "" : getSavePath()) + fileName;
try {
FileOutputStream fs = new FileOutputStream(filePath);
fs.write(entityData, 0, entityData.length);
fs.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else
throw new RuntimeException("Something is wrong");
}
public String getSavePath()
{
return savePath;
}
public void setSavePath(String value)
{
savePath = value;
}
private String savePath;
/**
* A dictionary to store associations between resource ids and corresponding file names.
*/
private final Map<Integer, String> m_externalImages;
/**
* A dictionary to store associations between content types of resources we are going to store externally
* and corresponding file name templates.
*/
private final Map<String, String> s_templates = new HashMap<>();
}
it does work, thanks a lot!
must image be svg in the html, rather <img src...
?
@woshiwuqida,
You can also set a bitmap format for the output images as follows:
htmlOptions.setSlideImageFormat(SlideImageFormat.bitmap(1, "PNG"));
This is indeed useful, but it results in the converted HTML being all images, rather than a separation of images and text (editable state).
Presentation ppt = new Presentation(file.getInputStream());
HtmlOptions htmlOpt = new HtmlOptions(new LinkController(imagesPath));
//htmlOpt.setSlideImageFormat(SlideImageFormat.svg(new SVGOptions()));
htmlOpt.setShowHiddenSlides(true);
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false));
htmlOpt.setSlideImageFormat(SlideImageFormat.bitmap(1, "PNG"));
ppt.save(outputStream, SaveFormat.Html, htmlOpt);
@woshiwuqida,
Could you please share the presentation file you used and the output files, and describe the problem in more detail?
My original intention was to convert a PowerPoint presentation (PPT) into HTML, and to have the images in the HTML formatted as (I’m not sure about the class type as I’m not very familiar with front-end development), rather than in SVG format (since my rich text tool does not support it), nor in base64 encoding (hence why I posted asking if there was a way to save images separately. However, the method you provided, htmlOptions.setSlideImageFormat(SlideImageFormat.svg(new SVGOptions()));
, sets the images to SVG. Then you gave another method, htmlOptions.setSlideImageFormat(SlideImageFormat.bitmap(1, "PNG"));
, which turned both the images and text on each slide of the converted HTML into a single image).
So, my current question is: How can I convert a PPT to HTML while keeping the images as separate files (not in SVG format), and preserving the original text without converting it into images?
input pptx and output html&png.zip (6.0 MB)
@woshiwuqida,
Thank you for the details. I am working on the question and will get back to you soon.
@woshiwuqida,
In your case, the solution is to use HTML5 as following
Presentation presentation = new Presentation("precept7_raft_nosolutions.pptx");
Html5Options html5Options = new Html5Options();
html5Options.setEmbedImages(false);
presentation.save("output.html", SaveFormat.Html5, html5Options);
presentation.dispose();
but we have found some issues in PPTX to HTML5 conversion using your sample presentation file and we will investigate the case. We apologize for any inconvenience.
The issues you found earlier (filed as SLIDESJAVA-39386) have been fixed in Aspose.Slides for Java 24.11 (JAR).
You can check all fixes on the Release Notes page.
You can also find the latest version of our library on the Product Download page.