Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:55:53+00:00 2026-06-12T11:55:53+00:00

I’m having big problems with a code that should add watermark pictures (used as

  • 0

I’m having big problems with a code that should add watermark pictures (used as stationery) to a document before saving it as PDF. Inserting the picture to all relevant headers is no problem. But as soon as I try to strech the picture (shape) to the whole page width and height, Word 2007 (SP3) throws an exception. The same code works fine in Word 2010 (SP1). It doesn’t matter if I use the Office 12 or Office 14 interop assemblies (always used with “Embed Interop Types” true).

The exception thrown is the following:

System.Runtime.InteropServices.COMException (0x800A122C): Falscher Zeichnungselement-Typ für diesen Befehl.
   at Microsoft.Office.Interop.Word.Shape.set_RelativeHorizontalSize(WdRelativeHorizontalSize prop)
   at BEKO.PDB.AuxiliaryServices.Documents.WordCreationService.AddWatermarkToHeader(HeaderFooter header, String watermarkFilePath)

I don’t know exactly what the english error message would be, but the translation is something like “Invalid painting type (or maybe shape type) for this command”.

The weird thing is that it doesn’t always error on the same interop call. If I remove the line that sets the RelativeHorizontalSize property it fails when setting another property, like WidthRelative (with the same exception). If I add a line that sets shape.LeftRelative (to the “do not use” constant) it even fails on a line that otherwise works like shape.Top (again with the same exception).

The code I’m using is from a macro that was recorded in the failing Word 2007. I’m also correctly switching to the header SeekView before executing any header related code because I already needed that for some other header/footer code.

Here is the full code that adds the shape. It should just insert the picture and strech it to the full page size. Note: This method is only called for headers that are actually existing (headerFooter.Exists) and that are not linked to the previous (!headerFooter.LinkToPrevious).

private static void AddWatermarkToHeader(HeaderFooter header, string watermarkFilePath) {
   header.Range.Editors.Add(WdEditorType.wdEditorEveryone);

   Shape shape = header.Shapes.AddPicture(
      FileName: watermarkFilePath,
      LinkToFile: false,
      SaveWithDocument: true
   );

   shape.WrapFormat.AllowOverlap = (int)MsoTriState.msoTrue;
   shape.WrapFormat.Type = WdWrapType.wdWrapNone;

   shape.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
   shape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
   shape.Left = 0;
   shape.Top = 0;

   shape.RelativeHorizontalSize = WdRelativeHorizontalSize.wdRelativeHorizontalSizePage;
   shape.RelativeVerticalSize = WdRelativeVerticalSize.wdRelativeVerticalSizePage;
   shape.WidthRelative = 100;
   shape.HeightRelative = 100;

   shape.ZOrder(MsoZOrderCmd.msoSendBehindText);
}

Please give any advice how to fix this so that the code works with both Word 2007 and Word 2010.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:55:54+00:00Added an answer on June 12, 2026 at 11:55 am

    I realize this does not fix the code to run on both versions of Word as requested, but have you tried using absolute sizing for the image instead? Keep relative positionning, but use absolute sizing. Do you actually need relative sizing (i.e. do your documents contain multiple page sizes?).

    shape.Width = page.Width;
    shape.Height = page.Height;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.