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

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -