Skip to content

Instantly share code, notes, and snippets.

@farhan-raza
Created March 1, 2024 13:55
Show Gist options
  • Save farhan-raza/89cf9ed72bf7f9294bd7c1c87ff3423d to your computer and use it in GitHub Desktop.
Save farhan-raza/89cf9ed72bf7f9294bd7c1c87ff3423d to your computer and use it in GitHub Desktop.
Convert Word Document DOC DOCX to JPG PNG Image in C# .NET
// Load the input Word document
Aspose.Words.Document doc = new Aspose.Words.Document("Words.docx");
// Initialize an object of ImageSaveOptions class
Aspose.Words.Saving.ImageSaveOptions options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg);
// Set the "PageSet" to "0" to convert only the first page of a document.
options.PageSet = new Aspose.Words.Saving.PageSet(0);
// Set the image's brightness and contrast.
options.ImageBrightness = 0.3f;
options.ImageContrast = 0.7f;
// Set the horizontal resolution.
options.HorizontalResolution = 72f;
// Save output JPG image
doc.Save("Word-to-JPG.jpg", options);
// Load the input Word document
Aspose.Words.Document doc = new Aspose.Words.Document("Words.docx");
// Initialize an object of ImageSaveOptions class
Aspose.Words.Saving.ImageSaveOptions options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
// Set the horizontal resolution.
options.HorizontalResolution = 72f;
// Save output PNG image
doc.Save("Word-to-PNG.png", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment