|
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new text to the paragraph
IWParagraph paragraph = section.AddParagraph();
//Gets the image and convert to byte array
Image image = Image.FromFile("Image.png");
MemoryStream imageStream = new MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
byte[] imageBytes = imageStream.ToArray();
//Initializes new picture
WPicture picture = new WPicture(document);
//Loads an image from the byte array
picture.LoadImage(imageBytes);
//Sets height and width for the image
picture.Height = 100;
picture.Width = 150;
//Sets picture rotation in degree
picture.Rotation = 90;
//Adds image to the paragraph
paragraph.Items.Add(picture);
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close(); |