Convert Word Document to PNG
Contents
[
Hide
]
To convert a Word document to PNG, simply invoke the Save method and specify a file name with the “.PNG” extension.
See more details in the Save a Document documentation section.
The following code example shows how to convert each document page from DOC to PNG:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
public static void ConvertDocumentToPNG() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); | |
// Load a document | |
Document doc = new Document(dataDir + "SampleImages.doc"); | |
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(dataDir + "output.png", imageSaveOptions); | |
Console.WriteLine("\nDocument converted to PNG successfully."); | |
} | |
private class HandlePageSavingCallback : IPageSavingCallback | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_LoadingAndSaving(); | |
public void PageSaving(PageSavingArgs args) | |
{ | |
args.PageFileName = string.Format(dataDir + "Page_{0}.png", args.PageIndex); | |
} | |
} |
See also: