I am using the apache POI.XWPF library to create word documents. For the last couple of days I have been searching how to do double spaces for the whole document. I have checked the Apache javadocs and just by searching the internet but can't seem to find any answers.
I found the addBreak()
method but it won't work because the user will input multiple paragraphs and breaking those paragraphs into single lines seemed unreasonable. If this method is used per paragraph then it won't create the double space between each line but between each paragraph.
Here is a small part of the code I currently have.
public class Paper {
public static void main(String[] args) throws IOException, XmlException {
ArrayList<String> para = new ArrayList<String>();
para.add("The first paragraph of a typical business letter is used to state the main point of the letter. Begin with a friendly opening; then quickly transition into the purpose of your letter. Use a couple of sentences to explain the purpose, but do not go in to detail until the next paragraph.");
para.add("Beginning with the second paragraph, state the supporting details to justify your purpose. These may take the form of background information, statistics or first-hand accounts. A few short paragraphs within the body of the letter should be enough to support your reasoning.");
XWPFDocument document = new XWPFDocument();
//Calls on createParagraph() method which creates a single paragraph
for(int i=0; i< para.size(); i++){
createParagraph(document, para.get(i));
}
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream("ResearchPaper.docx");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
document.write(outStream);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//Creates a single paragraph with a one tab indentation
private static void createParagraph(XWPFDocument document, String para) {
XWPFParagraph paraOne = document.createParagraph();
paraOne.setFirstLineIndent(700); // Indents first line of paragraph to the equivalence of one tab
XWPFRun one = paraOne.createRun();
one.setFontSize(12);
one.setFontFamily("Times New Roman");
one.setText(para);
}
}
Just to make sure my question is clear, I am trying to find out how to double space a word document (.docx). So between each line there should be one line of space. This is the same thing as pressing ctrl+2 when editing a word document.
Thank you for any help.