Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. 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

Scheduled Pinned Locked Moved ASP.NET
tutorialworkspace
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raghvendrapanda
    wrote on last edited by
    #1

    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

    Y 1 Reply Last reply
    0
    • R raghvendrapanda

      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

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      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?

      R 1 Reply Last reply
      0
      • Y Yusuf

        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?

        R Offline
        R Offline
        raghvendrapanda
        wrote on last edited by
        #3

        Would u please guide me how i can do by taking length into consideration. Thanks, Harish

        Y 1 Reply Last reply
        0
        • R raghvendrapanda

          Would u please guide me how i can do by taking length into consideration. Thanks, Harish

          Y Offline
          Y Offline
          Yusuf
          wrote on last edited by
          #4

          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?

          R 1 Reply Last reply
          0
          • Y Yusuf

            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?

            R Offline
            R Offline
            raghvendrapanda
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups