Page 1 of 1

[WORD] - Watermaks - programticaly

PostPosted: Fri Feb 14, 2014 1:22 am
by marcel_cap
Hello,

I would like to add a watermark to a word document programmatically

I would like to create a function like :
addWartermark(doc, String watermarkText)

I see the sample : Watermark.java, but to add a string xml is a litle bit dirty ...
Furethemore, I would like to be able to add watermark to existing files. (wich can have existing header, and existing watermark ...)


Thans,

Re: [WORD] - Watermaks - programticaly

PostPosted: Fri Feb 14, 2014 6:55 am
by jason
You can use the webapp (see link in menu above) to generate code.

Re: [WORD] - Watermaks - programticaly

PostPosted: Fri Feb 14, 2014 10:16 pm
by marcel_cap
Thanks !

I just have a bug when I had a watermark in a docx document that have an existing header.

It had 2 lines above the header (see capture), do you have an idea why ?

You can reproduce by executing Watermark.java. (and load an existing file with an header)

Code: Select all
       File fin = new File(System.getProperty("user.dir") + "/waterMarkTest.docx");

//        WordprocessingMLPackage wmlPackage = WordprocessingMLPackage
//                .createPackage();
      WordprocessingMLPackage wmlPackage = WordprocessingMLPackage
      .load(fin);

      Relationship relationship = createHeaderPart(wmlPackage);
      createHeaderReference(wmlPackage, relationship);
        File f = new File(System.getProperty("user.dir") + "/waterMarksample.docx");
        wmlPackage.save(f);