Hi, I am new in C# language.
I want to extract images from MS word and reset pictures and the size of each image in MS word and store them into Folder.
I have done the extraction of each image from MS word and store it into a folder. but I can't reset the picture and size of that particular image. (For reset the picture and size shortcut key for MS word - (Alt + JP + Q +S))
So I thought If I use any MS word Application shortcut Keypress events (Alt + JP + Q +S ) after inlineShape.Select(); line .in SaveInlineShapeToFile function then it' can be work, Can anyone help me to solve this problem. How can I use shortcut Key events activity for MS WORD file in this scenario?
- static void Main(string[] args)
- {
- var wordApplication = new Application();
- var document = wordApplication.Documents.Open(@"C:\Users\Desktop\Imagedocextract\Testpic.docx");
- for (var i = 1; i <= wordApplication.ActiveDocument.InlineShapes.Count; i++)
- {
- var inlineShapeId = i;
- var thread = new Thread(() => SaveInlineShapeToFile(inlineShapeId, wordApplication));
- thread.SetApartmentState(ApartmentState.STA);
- thread.Start();
- thread.Join();
- }
- wordApplication.Quit();
- Console.ReadLine();
- }
- protected static void SaveInlineShapeToFile(int inlineShapeId, Application wordApplication)
- {
- var inlineShape = wordApplication.ActiveDocument.InlineShapes[inlineShapeId];
- inlineShape.Select();
- wordApplication.Selection.Copy();
-
- if (Clipboard.GetDataObject() != null)
- {
- var data = Clipboard.GetDataObject();
-
- if (data != null && data.GetDataPresent(DataFormats.Bitmap))
- {
-
- var image = (Image)data.GetData(DataFormats.Bitmap, true);
- var currentBitmap = new Bitmap(image);
-
- currentBitmap.Save(@"C:\Users\Desktop\Imagedocextract\SaveImage\" + String.Format("img_{0}.jpg", inlineShapeId));
- }
- }
- }