IOT Virtual Conference - Register now to book your ticket and get updates
x
CONGRATULATIONS! C# Corner Q1, 2021 MVPs Announced
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forumguidelines
saikat banik
2k
36
570
How to reset pictures and the size of the image in word file using C#
Aug 5 2020 9:43 AM
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();
// Select each image from MS Word file
wordApplication.Selection.Copy();
// Check data is in the clipboard
if
(Clipboard.GetDataObject() !=
null
)
{
var data = Clipboard.GetDataObject();
// Check if the data conforms to a bitmap format
if
(data !=
null
&& data.GetDataPresent(DataFormats.Bitmap))
{
// Fetch the image and convert it to a Bitmap
var image = (Image)data.GetData(DataFormats.Bitmap,
true
);
var currentBitmap =
new
Bitmap(image);
// Save the bitmap to a file
currentBitmap.Save(@
"C:\Users\Desktop\Imagedocextract\SaveImage\" + String.Format("
img_{0}.jpg", inlineShapeId));
}
}
}
Reply
Answers (
4
)
Check each digit from a number if is odd or even
Store Record In Gujarati Language In server server