none
[WORD 2010] Add a background picture into a document

    Question

  • Hello,

    I want to add a background picture to a Word document. I use this code:

    myDoc.ActiveWindow.View.Type = Word.WdViewType.wdWebView;
    myDoc.Background.Fill.UserPicture("my_image.jpeg");
    

    It works but the background image is repeated. How can i set my background image as no-repeat ?

    Thanks

    Saturday, June 04, 2011 12:39 PM

Answers

  • Try something like this:

     

      With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture _
          (FileName:="C:\Images\MyPicture.jpg", LinkToFile:=False, _
          SaveWithDocument:=True)
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Top = 0
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .Left = 0
        .LockAspectRatio = False
        .Height = ActiveDocument.PageSetup.PageHeight
        .Width = ActiveDocument.PageSetup.PageWidth
      End With


    Regards, Hans Vogelaar
    Sunday, June 05, 2011 3:26 PM

All replies

  • Create an image the size of the page...
    Regards, Hans Vogelaar
    Saturday, June 04, 2011 7:54 PM
  • I already did that and it doesn't work...

    My image never fill my document entirely. I worked with sections sizes.

    I used msdn help to find the code i posted before: http://msdn.microsoft.com/fr-fr/library/microsoft.office.tools.word.document.background%28v=vs.80%29.aspx

    But how can set the image as no-repeat ? Is there a specific property ?

    Thanks in advance, and sorry for my bad english i'm french

     


    Saturday, June 04, 2011 9:31 PM
  • If you want the image to only appear on the first page of a section, set the Header/Footer to "different first page" and then position your image in the first page of the section in which you want it to appear. For this technique to work, the image must be in the Header. It's important to recognize that the header area is not limited to just the few lines on the top of a page. The header area is actually a full page layer upon which the body of your document is overlayed.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com
    Sunday, June 05, 2011 1:40 AM
  • I'm sorry i didn't really understand what you said.

    I just want to add a background image to the word document i generate programmaticaly.

    These documents are always single-page documents.

    Thanks

    Sunday, June 05, 2011 10:37 AM
  • Try something like this:

     

      With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture _
          (FileName:="C:\Images\MyPicture.jpg", LinkToFile:=False, _
          SaveWithDocument:=True)
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Top = 0
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .Left = 0
        .LockAspectRatio = False
        .Height = ActiveDocument.PageSetup.PageHeight
        .Width = ActiveDocument.PageSetup.PageWidth
      End With


    Regards, Hans Vogelaar
    Sunday, June 05, 2011 3:26 PM
  • Thanks a lot ! it's exactly what i expected ! You helped me a lot thanks !
    Monday, June 06, 2011 9:36 AM