Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8647403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:03:47+00:00 2026-06-12T13:03:47+00:00

My object is to read a .docx file and to display the text of

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:03:49+00:00Added an answer on June 12, 2026 at 1:03 pm

    HTML ignores line breaks. So, while a string like “Hello there\nLine 2\n” renders fine in the console as

    Hello There
    Line 2
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read that using Object.prototype to attach functions to custom JavaScript objects is more
I read that: Object sync = new Object(); /* inter to monitor */ try
I have read about application object in android site but I couldn't understand. What
You always read that for-in loops should check o.hasOwnProperty(k) to skip over Object.prototype. Well,
I think I read somewhere that some modules only have object oriented interfaces (
I've read and I believe I understand what C#'s using statement does (please correct
I'm making an Android application that has to read some values from a JSON
I just tried to read back an object I wrote to a file. I
I'm writing a tool to do some minor text replacement in a DOCX file,
I try to write and read object of class into and from binary file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.