NullReferenceException is thrown when Document.Save() method is called. I use Aspose.Words version 16.2.0.0. Here is a full code (file 16.docx is attached):
public class HandleImageSaving1 : Aspose.Words.Saving.IImageSavingCallback
{
void Aspose.Words.Saving.IImageSavingCallback.ImageSaving(Aspose.Words.Saving.ImageSavingArgs e)
{
e.ImageStream = new MemoryStream();
e.KeepImageStreamOpen = false;
}
}
public void TestDocumentSave()
{
using (var stream = new FileStream(@"C:\16.docx", FileMode.Open))
{
AsposeLicenseController.GetAsposeLicense();
Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Docx;
Aspose.Words.Document inputDocument = new Aspose.Words.Document(stream, loadOptions);
Aspose.Words.Saving.HtmlSaveOptions saveOptions = new Aspose.Words.Saving.HtmlSaveOptions();
saveOptions.ImageSavingCallback = new HandleImageSaving1();
saveOptions.PrettyFormat = true;
using (var processingStream = new MemoryStream())
{
inputDocument.Save(processingStream, saveOptions); // exception is thrown here!
}
}
}