Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active November 19, 2022 03:15
Code to Resize a Picture in Word using C#. For more details: https://kb.aspose.com/words/net/how-to-resize-a-picture-in-word-using-csharp/
using Aspose.Words;
using Aspose.Words.Drawing;
namespace AsposeProjects
{
class Program
{
static void Main(string[] args) // Main function to resize image in Word using C#
{
// Initialize license
License lic = new License();
lic.SetLicense("Aspose.Total.lic");
// Create a new Word document
Document doc = new Document();
// Create New Document.
DocumentBuilder docBuilder = new DocumentBuilder(doc);
// Insert the image title before resizing
docBuilder.Write("Image Before Resize");
// Insert an image into the loaded word file
Shape image = docBuilder.InsertImage("ImageToResize.jpg");
// Write the next text in the document for the resized image
docBuilder.Write("ReSize image ");
// Insert another instance of the image and get its reference
image = docBuilder.InsertImage("ImageToResize.jpg");
// Change image size
image.Width = ConvertUtil.InchToPoint(0.75);
image.Height = ConvertUtil.InchToPoint(0.75);
// Save the document with the original and resized image
docBuilder.Document.Save("FileWithImages.docx");
System.Console.WriteLine("Image resized successfully");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment