We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Java toString compatibility forces insecure operations

We work with sensitive documents and need to be able to say “we encrypt all data at rest.” Using Aspose.Words for Java to convert files makes it impossible to say so.

In particular, we need to keep all documents in memory (never on disk) unless they are encrypted. As far as I am aware, Aspose does not support reading/writing files encrypted at the application layer. So that leaves us with storing in memory.

However, when we try to convert files to docx (and maybe other formats?) using toString, which would keep it in memory, we get an error: “Exporting fragments of a document in this format is not supported.”

Is there some other way to convert files without writing to disk? Or a way to encrypt? Or can this toString incompatibility be fixed, and if so, when?

@bmulhollandrecital The Node.toString is not supposed to be used to convert document to DOCX, it accepts only HTML and TEXT save formats. If you need to convert the document to DOCX in memory, you should use Document.save method overload that accepts OutputStream as a parameter.

Thanks, that helps me here.

Product feedback for the team: It’s confusing to have a toString method that only supports one format. At the least, it should be clearer in the docs: https://reference.aspose.com/words/java/com.aspose.words/Document#toString(com.aspose.words.SaveOptions) HTML is not listed in the index of methods at the top of that page, for example, and text is not mentioned at all.

Also, just in terms of developer experience, having toString for some formats and save for others isn’t very natural or consistent.

@bmulhollandrecital That you for your feedback. We will update the documentation.
Also, not all document formats supported by Aspose.Words are textual, like TEXT or HTML. So it is impossible to represent them as string. For example DOCX and ODT documents are a ZIP archives, DOC format is binary format. toString method with SaveFormat has been added as a convenient method for converting a particular node to TEXT or HTML. When you save the whole document, you should use Document.save for saving the document.