2

i am having an issue trying to add images to a word document after the last image/word, trying to add a new page and adding the image to this would work as well.

this is the code i have so far for inserting the image.

Document aDoc;
            object isVisible = false;
            object readOnly = true;
            wordApp.Visible = false;
            aDoc = wordApp.Documents.Open(
                ref filename, ref MISSING,
                ref readOnly, ref MISSING, ref MISSING, ref MISSING,
                ref MISSING, ref MISSING, ref MISSING, ref MISSING,
                ref MISSING, ref isVisible, ref MISSING, ref MISSING,
                ref MISSING, ref MISSING);
            aDoc.Activate();
object range = aDoc.Content.End ;
aDoc.InlineShapes.AddPicture(@"C:\fullImagePath\Image.jpg", MISSING,MISSING, range)

i keep getting a type mismatch error

i also tried adding a new page but this deletes the data already existing on the word document adds a new page but adds the image on the 1st page.

aDoc.Content.InsertBreak(WdBreakType.wdPageBreak);
aDoc.InlineShapes.AddPicture(@"C:\fullImagePath\Image.jpg");

i am quite new to using Interop so i am a bit confused on how to do things

Shailesh Rama
  • 158
  • 3
  • 13
  • i tried adding aDoc.Paragraphs[1].Application.Selection.InsertParagraphAfter(); aDoc.Paragraphs[1].Application.Selection.InlineShapes.AddPicture(@"C:\FullImagePath\Image.JPG"); and this adds the image in the middle of the other content already in the document – Shailesh Rama Dec 08 '11 at 11:42

1 Answers1

3
aDoc.Application.ActiveDocument.Shapes.get_Item("Rectangle 6").Select(); //finds the 1st image
            aDoc.Application.Selection.MoveDown(WdUnits.wdScreen, 2);// adds tow pagedown presses
            aDoc.Application.Selection.InlineShapes.AddPicture(@"C:\fullImagePath\Image.JPG");//adds image on new page
            aDoc.Application.Selection.InsertBreak(WdBreakType.wdPageBreak);//adds a page break
            aDoc.Application.Selection.InlineShapes.AddPicture(@"C:\fullImagePath\Image.gif");//adds image on new page

i used the above to get the images in the places i needed them to be

Shailesh Rama
  • 158
  • 3
  • 13