We’re using Aspose of version 13.3.0.0 to convert word document to jpeg.
For majority of documents the functionality works with no problem.
But there are some which generate null reference exception.
Piece of code we use(in vb.net):
Dim result As Stream = New MemoryStream()
Try
Dim doc As Aspose.Words.Document = New Aspose.Words.Document(documentStream)
Dim imageOptions As New Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Jpeg)
imageOptions.PageIndex = 0
imageOptions.PageCount = 1
doc.Save(result, imageOptions)
Catch ex As Exception
End Try
The document which produces such error is in attachments.
After an initial test with the licensed latest (21.7) version of Aspose.Words for .NET, we were unable to reproduce this exception on our end. Please check below Aspose.Words for .NET 21.7 generated JPEG Image files:
Please note that PageCount and PageIndex properties are no longer part of the ImageSaveOptions Class. We have now added PageSet and PageRange Classes. Here is the C# example to convert all pages in Word Document to separate JPEG image files:
Document doc = new Document("C:\\Temp\\Some test.docx");
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Jpeg);
PageRange pageRange = new PageRange(0, doc.PageCount - 1);
imageSaveOptions.PageSet = new PageSet(pageRange);
imageSaveOptions.PageSavingCallback = new HandlePageSavingCallback();
doc.Save("C:\\temp\\awnet-21.7.jpg", imageSaveOptions);
private class HandlePageSavingCallback : IPageSavingCallback
{
public void PageSaving(PageSavingArgs args)
{
args.PageFileName = string.Format(@"C:\Temp\Page_{0}.jpg", args.PageIndex);
}
}
So, we suggest you to please upgrade to the latest version of Aspose.Words for .NET.