Hi,
I have a Word document whose Top Margin was reduced to fit a lot of content on a single page.
When I use the following code to add a watermark, the TopMargin from the original document is lost and now the document spans two pages.
I know I can explictily set the TopMargin in code; the problem is that I have been unable to capture the original TopMargin value from the template (in code). A hard coded TopMargin value is not acceptable. In other words I need to preserve whatever TopMargin value was set in ANY Word document where I need to apply a watermark. Aspose Words seems to reset the TopMargin to the default.
Here is the code for adding the watermark…
String imageFile = "D:/temp/AsposeTest/watermark.jpg";
String inFileName = "D:/temp/AsposeTest/DotWithSmallTopMargin.dot";
String outFileName = "D:/temp/AsposeTest/DocWithWatermark.doc";
Document doc = new Document(inFileName);
DocumentBuilder builder =new DocumentBuilder(doc);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
// Insert a floating picture.
Shape shape = builder.insertImage(imageFile);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
// Position the image in the center of the page.
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
shape.setVerticalAlignment(VerticalAlignment.CENTER);
doc.save(outFileName);
Attached are a test Word docment and watermark image.
Thank You