Hi,
I tried with the above code sample but still I am facing some issues.
My input document has paragraph, a table and after there two paragraphs. When I am trying to append the line break with above code, it is working for the paragraph above the table. But the spacing for the text which is after the table is lost (PFA output file). Below is the code which i am using.
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
System.out.println(para.getText() + "doc.getNodeType(); " + doc.getNodeType());
para.getParagraphFormat().setSpaceBefore(0);
para.getParagraphFormat().setSpaceAfter(0);
if (para.isListItem())
{
com.aspose.words.List list0 = para.getListFormat().getList();
ListLevel level0 = list0.getListLevels().get(para.getListFormat().getListLevelNumber());
ECMUtils.levelNumber = para.getListFormat().getListLevelNumber();
if (ECMUtils.levelNumber == 0)
{
ECMUtils.lineSpacingDecrement = 3.6D;
if (!(isFirstPara))
{
para.getParagraphFormat().setSpaceBefore(ECMUtils.lineSpacingDecrement);
isFirstPara = true;
}
}
level0.setNumberPosition(ECMUtils.levelNumber \*10);
level0.setTabPosition(11 + ECMUtils.levelNumber \*10);
level0.setTrailingCharacter(3);
level0.setTextPosition(level0.getTabPosition());
if (ECMUtils.lineSpacingDecrement != -1.44D)
{
ECMUtils.lineSpacingDecrement = 3.6D - (ECMUtils.levelNumber \*1.26D);
}
para.getParagraphFormat().setSpaceAfter(ECMUtils.lineSpacingDecrement);
} else {
isFirstPara = true;
para.getParagraphFormat().setSpaceBefore(ECMUtils.LINE_SPACING);
para.getParagraphFormat().setSpaceAfter(ECMUtils.LINE_SPACING);
//para.getParagraphFormat().setSpaceBefore(0.16);
//para.getParagraphFormat().setSpaceAfter(0.16);
}
System.out.println("para text " + para.getText());
if (doc.getChildNodes(NodeType.TABLE, true).getCount() > 0)
{
for (int i = 0; i < doc.getChildNodes(NodeType.TABLE, true).getCount(); i++)
{
Table table = (Table)doc.getChild(NodeType.TABLE, i, true);
if (table.getPreviousSibling() != null && table.getPreviousSibling().getNodeType() == NodeType.PARAGRAPH)
{
para.getParagraphFormat().setSpaceBefore(0);
para.getParagraphFormat().setSpaceAfter(0);
((Paragraph)table.getPreviousSibling()).getParagraphFormat().setSpaceAfter(0.16);
((Paragraph)table.getPreviousSibling()).getParagraphFormat().setSpaceBefore(0.16);
}
}
}
}
doc.save(fileNameandPath);
FYR – the values for ECMUtils.levelNumber is 0 and ECMUtils.LINE_SPACING = 3.6
I am creating the input document using html file, input.html
I have attached the input, output and desired output documents.
Please tell where i am going wrong