How set watermark in word file using Aspose.Word for Java -


here code. not working.

private static void insertwatermarktext(document doc, string watermarktext) throws exception     {         // create watermark shape. wordart shape.         // free try other shape types watermarks.         shape watermark = new shape(doc, shapetype.text_plain_text);      // set text of watermark.     watermark.gettextpath().settext(watermarktext);     watermark.gettextpath().setfontfamily("arial");     watermark.setwidth(500);     watermark.setheight(100);     // text directed bottom-left top-right corner.     watermark.setrotation(-40);     // remove following 2 lines if need solid black text.     watermark.getfill().setcolor(color.gray); // try lightgray more word-style watermark     watermark.setstrokecolor(color.gray); // try lightgray more word-style watermark      // place watermark in page center.     watermark.setrelativehorizontalposition(relativehorizontalposition.page);     watermark.setrelativeverticalposition(relativeverticalposition.page);     watermark.setwraptype(wraptype.none);     watermark.setverticalalignment(verticalalignment.center);     watermark.sethorizontalalignment(horizontalalignment.center);      // create new paragraph , append watermark paragraph.     paragraph watermarkpara = new paragraph(doc);     watermarkpara.appendchild(watermark);      // insert watermark headers of each document section.     (section sect : doc.getsections())     {         // there 3 different headers in each section, since want         // watermark appear on pages, insert headers.         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_primary);         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_first);         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_even);     } } 

i have resolved issue. conflict of jar file. here got new jar files. code working. here updated code :

/**  * inserts watermark document.  *  * @param doc input document file.  * @param watermarktext text of watermark.  */ private static void insertwatermarktext(document doc, string watermarktext) throws exception {     // create watermark shape. wordart shape.     // free try other shape types watermarks.     shape watermark = new shape(doc, shapetype.text_plain_text);      // set text of watermark.     watermark.gettextpath().settext(watermarktext);     watermark.gettextpath().setfontfamily("arial");     watermark.setwidth(500);     watermark.setheight(100);     // text directed bottom-left top-right corner.     watermark.setrotation(-40);     // remove following 2 lines if need solid black text.     watermark.getfill().setcolor(color.gray); // try lightgray more word-style watermark     watermark.setstrokecolor(color.gray); // try lightgray more word-style watermark      // place watermark in page center.     watermark.setrelativehorizontalposition(relativehorizontalposition.page);     watermark.setrelativeverticalposition(relativeverticalposition.page);     watermark.setwraptype(wraptype.none);     watermark.setverticalalignment(verticalalignment.center);     watermark.sethorizontalalignment(horizontalalignment.center);      // create new paragraph , append watermark paragraph.     paragraph watermarkpara = new paragraph(doc);     watermarkpara.appendchild(watermark);      // insert watermark headers of each document section.     (section sect : doc.getsections())     {         // there 3 different headers in each section, since want         // watermark appear on pages, insert headers.         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_primary);         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_first);         insertwatermarkintoheader(watermarkpara, sect, headerfootertype.header_even);     }     system.out.println("watermark set"); }  private static void insertwatermarkintoheader(paragraph watermarkpara, section sect, int headertype) throws exception {     headerfooter header = sect.getheadersfooters().getbyheaderfootertype(headertype);      if (header == null)     {         // there no header of specified type in current section, create it.         header = new headerfooter(sect.getdocument(), headertype);         sect.getheadersfooters().add(header);     }      // insert clone of watermark header.     header.appendchild(watermarkpara.deepclone(true)); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -