Last active
September 24, 2021 16:18
-
-
Save aspose-com-kb/eaabe263f15eed0aa76d517438ef3daa to your computer and use it in GitHub Desktop.
How to Convert Word Document to Images in C#. More details and steps can be found here https://kb.aspose.com/words/net/how-to-convert-word-document-to-images-in-c-sharp/
This file contains hidden or 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
| using Aspose.Words; | |
| using Aspose.Words.Saving; | |
| using System; | |
| namespace KBCodeExamples | |
| { | |
| class How_to_Convert_Word_Document_to_Images_in_C_sharp | |
| { | |
| public static void ConvertWordDocumenttoImages(String wordtoimage_directory) | |
| { | |
| //Set Aspose license before converting word document to images | |
| //using Aspose.Words for .NET | |
| Aspose.Words.License AsposeWordsLicense = new Aspose.Words.License(); | |
| AsposeWordsLicense.SetLicense(wordtoimage_directory + @"Aspose.Words.lic"); | |
| //Import the document into Aspose.Words DOM. | |
| //The document can be imported from disk or memory stream. | |
| Document doc = new Document(wordtoimage_directory + "input.docx"); | |
| //Set ImageSaveOptions to convert document pages to image. | |
| ImageSaveOptions wordpagestoimage = new ImageSaveOptions(SaveFormat.Png); | |
| //Set page ranges to convert all word pages to image. | |
| PageRange pagerange = new PageRange(0, doc.PageCount - 1); | |
| wordpagestoimage.PageSet = new PageSet(pagerange); | |
| wordpagestoimage.PageSavingCallback = new Word_Pages_To_Images(); | |
| //Save document's pages to PNG | |
| doc.Save(@"output.png", wordpagestoimage); | |
| } | |
| //Implement this interface if you want to control how Aspose.Words saves separate pages | |
| //when saving a document to fixed page formats. | |
| class Word_Pages_To_Images : IPageSavingCallback | |
| { | |
| public void PageSaving(PageSavingArgs args) | |
| { | |
| args.PageFileName = string.Format(@"output_{0}.png", args.PageIndex); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment