My object is to read a .docx file and to display the text of that on the view(Webpage).
I am using apache POI to read a .docx file in Grails Application
Please suggest me a way to display the output on view without loosing Blankspaces and LineBreaks.
My .docx document content
This is a .docx document ...
this is second line
this is third line
Result on Groovy console after reading when i am printing :
This is a .docx document ...
this is second line
this is third line
But when i pass the output to view It becomes
This is a .docx document ... this is second line this is third line
.
My code is :
import org.apache.poi.xwpf.usermodel.XWPFDocument
import org.apache.poi.xwpf.extractor.XWPFWordExtractor
...
String str = "E:\\Query.docx"
File docFile = null;
docFile = new File(str);
FileInputStream fis=new FileInputStream(docFile.getAbsolutePath());
XWPFDocument doc = new XWPFDocument(fis)
XWPFWordExtractor docExtractor = new XWPFWordExtractor(doc)
println docExtractor.getText()
...
if one can suggest me the way to iterate through each line of the document then i can easily get my result.
Please help me i have got stucked.
HTML ignores line breaks. So, while a string like “Hello there\nLine 2\n” renders fine in the console as
As HTML it’ll all show on the same line. You’ll need to replace the newline characters with some suitable HTML, eg
<br />or wrapping things in paragraph/div tags.