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)