How to replace text with image in word 2007 and save the file in .pdf format
-
How to replace text with image in word 2007 and save the file in .pdf format this is my code _wordapp.ActiveWindow.Selection.WholeStory(); _wordapp.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string temp = ""; temp = data.GetData(DataFormats.Text).ToString(); temp = temp.Replace("\r", ""); string[] arrtemp = temp.Split(Environment.NewLine.ToCharArray()); int pos = 0; for (int t = 0; t < arrtemp.Length; t++) { if (arrtemp[t].Contains("Sign1")) { pos = t; string fileName = GetSignPath(); //the picture file to be inserted Object oMissed = _aDoc.Paragraphs[pos].Range; //the position you want to insert Object oLinkToFile = false; //default Object oSaveWithDocument = true;//default _aDoc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); File.Delete(fileName); this.FindAndReplace("Sign1", ""); } } Its replacing at wrong place instead of where i wanted(i.e. in place of Sign1) Sign1 is the text given in the Word 2007 to find and replace it with image Instead it is placing sumwhere else only in the .pdf file Please suggest me the code to solve it Its urgent Thanks, Harish
-
How to replace text with image in word 2007 and save the file in .pdf format this is my code _wordapp.ActiveWindow.Selection.WholeStory(); _wordapp.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string temp = ""; temp = data.GetData(DataFormats.Text).ToString(); temp = temp.Replace("\r", ""); string[] arrtemp = temp.Split(Environment.NewLine.ToCharArray()); int pos = 0; for (int t = 0; t < arrtemp.Length; t++) { if (arrtemp[t].Contains("Sign1")) { pos = t; string fileName = GetSignPath(); //the picture file to be inserted Object oMissed = _aDoc.Paragraphs[pos].Range; //the position you want to insert Object oLinkToFile = false; //default Object oSaveWithDocument = true;//default _aDoc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); File.Delete(fileName); this.FindAndReplace("Sign1", ""); } } Its replacing at wrong place instead of where i wanted(i.e. in place of Sign1) Sign1 is the text given in the Word 2007 to find and replace it with image Instead it is placing sumwhere else only in the .pdf file Please suggest me the code to solve it Its urgent Thanks, Harish
raghvendrapanda wrote:
Its replacing at wrong place instead of where i wanted(i
well your problem lies on the following code
raghvendrapanda wrote:
pos = t;
t is your array index not position index within your text. You need to take into consideration word length as well, don't you?
Yusuf May I help you?
-
raghvendrapanda wrote:
Its replacing at wrong place instead of where i wanted(i
well your problem lies on the following code
raghvendrapanda wrote:
pos = t;
t is your array index not position index within your text. You need to take into consideration word length as well, don't you?
Yusuf May I help you?
Would u please guide me how i can do by taking length into consideration. Thanks, Harish
-
Would u please guide me how i can do by taking length into consideration. Thanks, Harish
I already did, see my earlier message. You need to take the length of the word into account when calculating position first position = length of first word subsequent positions = last position + length of word at hand. You need to make up for spaces as well. Good Luck.
Yusuf May I help you?
-
I already did, see my earlier message. You need to take the length of the word into account when calculating position first position = length of first word subsequent positions = last position + length of word at hand. You need to make up for spaces as well. Good Luck.
Yusuf May I help you?
Hi Yusuf, Dude I tried but i am getting the exception. _wordapp.ActiveWindow.Selection.WholeStory(); _wordapp.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string temp = ""; int temp1 = 0; temp = data.GetData(DataFormats.Text).ToString(); temp = temp.Replace("\r", ""); //temp = System.Text.RegularExpressions.Regex.Replace(temp, @"\r", ""); temp1 = Convert.ToInt32(temp.Length); temp1 = temp.IndexOf("Sign1"); for (int t = arrtemp.Length - 1; t > 0; t--) { if (arrtemp[t].Contains("Sign1")) { //pos = t; string fileName = GetSignPath(); //the picture file to be inserted Object oMissed = _aDoc.Paragraphs[temp1].Range; //the position you want to insert Object oLinkToFile = false; //default Object oSaveWithDocument = true;//default _aDoc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); //_wordapp.Selection.InlineShapes.AddPicture(fileName,ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); _wordapp.Selection.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); File.Delete(fileName); this.FindAndReplace("Sign1", fileName); } I am getting exception at below mentioned line Object oMissed = _aDoc.Paragraphs[temp1].Range; An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsFormsApp_Templates.exe Additional information: The requested member of the collection does not exist. Need help.Got stuck at this place. Thanks, Harish