java - How to print pretty JSON using docx4j into a word document? -
i want print simple pretty json string (containing multiple line breaks - many \n) word document. tried following docx4j prints contents inline in 1 single line (without \n). ideally should print multiline pretty json recognising "\n" json string contains :
1)
wordmlpackage.getmaindocumentpart().addparagraphoftext({multiline pretty json string})
2)
objectfactory factory = context.getwmlobjectfactory(); p p = factory.createp(); text t = factory.createtext(); t.setvalue(text); r run = factory.creater(); run.getcontent().add(t); p.getcontent().add(run); ppr ppr = factory.createppr(); p.setppr(ppr); pararpr pararpr = factory.createpararpr(); ppr.setrpr(pararpr); wordmlpackage.getmaindocumentpart().addobject(p);
looking help. thanks.
the docx file format doesn't treat \n newline.
so you'll need split string on \n, , either create new p, or use w:br, so:
br br = wmlobjectfactory.createbr(); run.getcontent().add( br);
Comments
Post a Comment