Hi,
I’m upgrading Aspose Word from version 19.6 to 20.10, but got an issue when saving word document to image.
In my current project using Aspose Word 19.6, I used source code from Convert Word Document to PNG|Aspose.Words for .NET to saving a word document to image file. But in version 20.10, the API changed and can’t use the old source code anymore.
Can you give me some documentation for the update in API?
Thank you
@dunghnguyen,
Please use the following C# code of Aspose.Words for .NET API to convert all pages in Word Document to separate PNG image files:
Document doc = new Document(@"C:\Temp\input.docx");
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
PageRange pageRange = new PageRange(0, doc.PageCount - 1);
imageSaveOptions.PageSet = new PageSet(pageRange);
imageSaveOptions.PageSavingCallback = new HandlePageSavingCallback();
doc.Save(@"C:\Temp\output.png", imageSaveOptions);
And the definition of Class implementing the IPageSavingCallback interface:
private class HandlePageSavingCallback : IPageSavingCallback
{
public void PageSaving(PageSavingArgs args)
{
args.PageFileName = string.Format(@"C:\Temp\Page_{0}.png", args.PageIndex);
}
}
Please also refer to PageRange Class and ImageSaveOptions.PageSet Property.