java - Exception using POI to set watermark in doc file -


i'm using poi-3.9, set watermark in .doc

here code:

public void setwartermark() {     string filesname = "example1.doc";     try     {          xwpfdocument xdoc = new xwpfdocument(new fileinputstream(filesname));         xwpfheaderfooterpolicy xfooter = new xwpfheaderfooterpolicy(xdoc);         xfooter.createwatermark("my watermark");         system.out.println("done");     }     catch(exception e) {         e.printstacktrace();     } } 

the console show:

org.apache.poi.poixmlexception: org.apache.poi.openxml4j.exceptions.invalidformatexception: package should contain content type part [m1.13] @ org.apache.poi.util.packagehelper.open(packagehelper.java:41) @ org.apache.poi.xwpf.usermodel.xwpfdocument.<init>(xwpfdocument.java:120) @ com.avi.test.readdoc.main(readdoc.java:46) 

you using .doc format, hence exception occurs. xwpfdocument works .docx format. try changing format , work.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -