Free Support Forum - aspose.com

Can not add image to odd headers

Hello,

I am currently testing ASPOSE.components.

We need to add a watermark sign or other image to each page of the word document.

As you proposed I tried your example of adding an image to each header.

Using the code below I can not add an image to the header of odd numbered pages.

Can you tell me where is my mistake ?

Is there any other way to add a picture to each page of a document ?

Thanks a lot in advance for your help !

Regards,

Manuela

Enclosed please find the code:

private Sub InsertMuster(MyBuilder as Aspose.Words.DocumentBuilder)

Dim image As System.Drawing.Image = System.Drawing.Image.FromFile("C:\temp\ASPOSE\MyPic.jpg")

Dim useablePageWidth As Double = myBuilder.PageSetup.PageWidth - myBuilder.PageSetup.LeftMargin - myBuilder.PageSetup.RightMargin

Dim useablePageHeight As Double = myBuilder.PageSetup.PageHeight - myBuilder.PageSetup.TopMargin - myBuilder.PageSetup.BottomMargin

'Calculate image width and height in points.

Const PointsPerInch As Integer = 72

Dim imageWidth As Double = (image.Width / image.HorizontalResolution) * PointsPerInch

Dim imageHeight As Double = (image.Height / image.VerticalResolution) * PointsPerInch

'Calculate image left and top position so it appears in the centre of the page.

Dim imageLeft As Double = (useablePageWidth - imageWidth) / 2

Dim imageTop As Double = (useablePageHeight - imageHeight) / 2

'Insert a floating picture.

myBuilder.InsertImage(image, RelativeHorizontalPosition.Margin, imageLeft, RelativeVerticalPosition.Margin, imageTop, imageWidth, imageHeight, WrapType.None, WrapSide.Both, True, Nothing)

End Sub

myBuilder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderFirst)

InsertMuster(myBuilder)

myBuilder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderPrimary)

InsertMuster(myBuilder)

myBuilder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderEven)

InsertMuster(myBuilder)

To add an image to each page of the word document you do not need to set all headers in your document. You only need to set the primary header:

myBuilder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderPrimary)

InsertMuster(myBuilder)

It will set the image to appear on all pages in your document.

Please pay attention that headers/footers are property of the document section, not the document itself. So, if you have more than one section in your document you need to insert image to other sections primary header too.

Thanks a lot for your fast reply.

Now, i got it working - great !

Kind regards,

Manuela