Word text justify issue

Hi,

i am creating a document with justified text and adding multiple paragraph in one string.

when the last line of the para dose not contain enough word to fill the line it spreads the words with large space in between

i same can be done by shift enter in word.

which property should i use to solve this.

Hi,

Thanks for your inquiry. You can adjust your paragraph formatting by using following code snippet.

Paragraph

para = new Paragraph(doc);
// We can set some formatting for the paragraph
para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

For more details, please visit following links:
https://reference.aspose.com/words/java/com.aspose.words/paragraphalignment/
https://reference.aspose.com/words/java/com.aspose.words/paragraph/

Hope this will help you.

Hi,

Thanks for your inquiry. I think ParagraphFormat.SpaceAfter Property and ParagraphFormat.SpaceBefore Property are what you are looking for.

Moreover, pressing SHIFT+ENTER inside MS Word inserts a manual line break character. Its Aspose.Words equivalent is ControlChar.LineBreak field.

Please let me know if I can be of any further assistance.

Best Regards,

hi

i am using this code

String clauseText = getFormattedClauseText(clause.getClauseText());
clauseText = clauseText + "\r";
builder.getParagraphFormat().setStyle(listStyleLevel1);
// builder.getListFormat().setList(list);
builder.getListFormat().setListLevelNumber(2);
builder.getFont().setSize(12);
builder.getFont().setName("Calibri");
builder.getFont().setBold(false);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.JUSTIFY);
builder.getParagraphFormat().setLeftIndent(0);

builder.writeln(clauseText);
builder.getFont().clearFormatting();
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);

I am generating a document like this.

using the above code in loop

see the text is between the para is spread across the line.

Hi,

Thanks for your inquiry. First of all, please note that DocumentExplorer is a very useful tool which easily enables us to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Below is the DOM structure of your document as viewed with DocumentExplorer:

http://www.aspose.com/community/photos/public-gallery/images/original/document.aspx

I have observed three reasons white spaces, TABs and Line Breaks. To remove, please follow up this code snippet:

Document doc = new Document("d:/temp/doctest.doc");
// Iterate through all paragraphs in the document
for (Run run: (Iterable <Run> ) doc.getChildNodes(NodeType.RUN, true))
{
    String RunNodeText = run.getText();
    // Removing multiple Tabs
    RunNodeText = RunNodeText.replaceAll(ControlChar.TAB, " ");
    // Removing Line Breaks
    RunNodeText = RunNodeText.replaceAll(ControlChar.LINE_BREAK, " ");
    // Removing multiple white spaces
    Pattern r1 = Pattern.compile("[ ]{2,}");
    Matcher m1 = r1.matcher(RunNodeText);
    RunNodeText = m1.replaceAll(" ");
    run.setText(RunNodeText);
}
doc.save("d:/temp/doctestOut10.doc");

I have attached output Word document file. Hope this will help you. In case of any ambiguity, please let me know.