apache poi - How to read docx file content in java api using poi jar -


i have done reading doc file i'm trying read docx file content. when searched sample code found many, nothing worked. check code reference...

import java.io.*; import org.apache.poi.xwpf.usermodel.xwpfdocument; import org.apache.poi.xwpf.extractor.xwpfwordextractor; import com.itextpdf.text.pdf.pdfwriter; import com.itextpdf.text.document; import com.itextpdf.text.paragraph;  public class createpdffordocx {  public static void main(string[] args) { inputstream fs = null;       document document = new document();     xwpfwordextractor extractor = null ;  try {      fs = new fileinputstream("c:\\datastore\\test.docx");     //xwpfdocument hdoc=new xwpfdocument(fs);     xwpfdocument hdoc=new xwpfdocument(opcpackage.open(fs));     //xwpfdocument hdoc=new xwpfdocument(fs);     extractor = new xwpfwordextractor(hdoc);     outputstream fileoutput = new fileoutputstream(new       file("c:/datastore/test.pdf"));     pdfwriter.getinstance(document, fileoutput);     document.open();     string filedata=extractor.gettext();     system.out.println(filedata);     document.add(new paragraph(filedata));     system.out.println(" pdf document created");         } catch(ioexception e) {             system.out.println("io exception");              e.printstacktrace();           } catch(exception ex) {              ex.printstacktrace();            }finally {                   document.close();              }   }//end of main() }//end of class 

for above code i'm getting following exception:

org.apache.poi.poixmlexception: java.lang.reflect.invocationtargetexception @ org.apache.poi.xwpf.usermodel.xwpffactory.createdocumentpart(xwpffactory.java:60) @ org.apache.poi.poixmldocumentpart.read(poixmldocumentpart.java:277) @ org.apache.poi.poixmldocument.load(poixmldocument.java:186) @ org.apache.poi.xwpf.usermodel.xwpfdocument.<init>(xwpfdocument.java:107) @ pagecode.createpdffordocx.main(createpdffordocx.java:20) caused by: java.lang.reflect.invocationtargetexception @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:67) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:521) @ org.apache.poi.xwpf.usermodel.xwpffactory.createdocumentpart(xwpffactory.java:58) ... 4 more caused by: java.lang.nosuchmethoderror: org/openxmlformats/schemas/wordprocessingml/x2006/main/ctstyles.getstylelist()ljava/util/list; @ org.apache.poi.xwpf.usermodel.xwpfstyles.ondocumentread(xwpfstyles.java:78) @ org.apache.poi.xwpf.usermodel.xwpfstyles.<init>(xwpfstyles.java:59) ... 9 more 

please thank you

this covered in apache poi faq! entry want i'm using poi-ooxml-schemas jar, code failing "java.lang.noclassdeffounderror: org/openxmlformats/schemas/something"

the short answer switch poi-ooxml-schemas jar full ooxml-schemas-1.1 jar. full answer given in faq


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -