What control do I have over images inserted into Word documents? Specifically, if I have an image that’s 640x480 @ 150dpi, I don’t want Word to perform any automatic scaling. Also, I’d like the option of adjusting the height and width of an image if desired.
I’m thinking that image processing can be done with the .NET Framework, but how do I stop Word from resizing the image?
Please check the following article in our offline Aspose.Words Programmer's Guide:
Programmer's Guide | Building Documents Dynamically | Inserting Document Elements
It is also available online on:
There you will find detailed description of various image inserting scenarios.
Basically, if you want to insert image without scaling you should use one oveload of InsertImage method. If you want to rescale it - then there is another overload.
I’ve confirmed that Word will automatically resize an image if it’s bigger than the page width minus the margins. There’s a “Reset” button if you right-click an image and select properties. Can I do this programmatically with Aspose.Words?
To insert image without rescaling use the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// save document and open it in MS Word to view results
string filename = Application.StartupPath + @"\testInsertImage Out.doc";
To change image size use the Height and Width properties of the corresponding Shape or InlineShape object:
InlineShape shape = (InlineShape)builder.InsertImage(@"D:\lastsupp.jpg");
// rescale image to 25% of the original size.
shape.Height = shape.Height / 4;
shape.Width = shape.Width / 4;
More 'intellectual' image rescaling and resizing (like fitting to page width or resetting to the original size) is not supported yet in our public API.