Save docx as markdown with outputStream

When i convert docx with images to markdown as a outputStream, i met a java.lang.IllegalStateException. What can i do for saving markdown as stream?

@wanghq09 To save markdown document into a stream you should either specify a folder where to store the images:

Document doc = new Document("C:\\Temp\\in.docx");
MarkdownSaveOptions opt = new MarkdownSaveOptions();
// Specify folder where images will be saved.
opt.setImagesFolder("C:\\Temp\\");
ByteOutputStream bos = new ByteOutputStream();
doc.save(bos, opt);

or store images as base64 inside markdown document:

Document doc = new Document("C:\\Temp\\in.docx");
MarkdownSaveOptions opt = new MarkdownSaveOptions();
// Instruct Aspose.Words to export images as base64 in MD document.
opt.setExportImagesAsBase64(true);
ByteOutputStream bos = new ByteOutputStream();
doc.save(bos, opt);

or use IImageSavingCallback to specify custom action on image export.

What to do if i just want to drop the images in the docx file

@wanghq09 If you would like to insert image into the document, you can use one of the DocumentBuilder.insertImage method overloads.

I mean how could i saving markdown document into a stream and discarding all pictures

@wanghq09 You can simply remove shapes from the document before saving the document to markdown:

Document doc = new Document("C:\\Temp\\in.docx");
        
// Remove shapes from the document.
doc.getChildNodes(NodeType.SHAPE, true).clear();
        
// Save to markdown
// ....