I wanted to print the style name for paragraph in the sample document "sample-docx.docx"
using openMainDocumentAndTraverse.java with little modification in the callback method to be
- Code: Select all
public List<Object> apply(Object o) {
String text = "";
if (o instanceof org.docx4j.wml.Text)
text = ((org.docx4j.wml.Text) o).getValue();
if (o instanceof org.docx4j.wml.P)
text += "=====" + " " + ((org.docx4j.wml.P) o).getPPr().getPStyle().getVal();
System.out.println(indent + o.getClass().getName() + " \""+ text + "\"");
return null;
}
I get null pointer exception in this text "This is a document exhibiting basic docx features. " which style is Normal as there is no ppr object for this Paragraph
Why do I get this error ? or how can I get what I wanted to do ?
Thanks