Free Support Forum - aspose.com

Cannot save image to disc

Hello Aspose,

I am evaluating aspose java for my software and I have issue saving .docx with images. This is my code.

public String convertDocxToHtml(byte[] doc) {
try {
ByteArrayInputStream is = new ByteArrayInputStream(doc);
HtmlSaveOptions options = new HtmlSaveOptions();
options.setImageSavingCallback(new HandleImageSaving());
Document asposedoc = new Document(is);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
asposedoc.save(outputStream, options);
String str = asposedoc.getText();
str = outputStream.toString();
return outputStream.toString();
} catch (Exception e) {
e.printStackTrace();
}
return “”;
}

public class HandleImageSaving implements IImageSavingCallback,
ISlideImageFormat {
public void imageSaving(ImageSavingArgs e) throws Exception {
if (e.getImageFileName().endsWith(".jpeg")) {
e.setImageFileName(e.getImageFileName().replace(".jpeg", “.jpg”));
}
}
}

Hello Aspose,

I’ve manage to fix the problem by adding following code into convertDocxToHtml:

options.setExportImagesAsBase64(true);

Regards,

Hi Ognjen,


It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,