Hi,
I’m trying to recreate all the paragraph styles of a document but couldn’t find a way recreate the borders.
Is it possible to do so?
You will find attached the document that contains the styles I need to recreate. The style that gives me trouble is the one untitled “AJentête”.
I’m now recreating another style which as a bullet list. This is the style “AJliste” in the attached document.
My code to recreate it is the following :
Style aJnormal = doc.getStyles().add(StyleType.PARAGRAPH, "AJnormal");
aJnormal.setBaseStyle("Normal");
//font
aJnormal.getFont().setSize(11);
//paragraph
aJnormal.getParagraphFormat().setAlignment(ParagraphAlignment.JUSTIFY);
aJnormal.getParagraphFormat().setSpaceBefore(6);
aJnormal.getParagraphFormat().setLineSpacingRule(LineSpacingRule.EXACTLY);
aJnormal.getParagraphFormat().setLineSpacing(13);
Style aJliste = doc.getStyles().add(StyleType.PARAGRAPH, "AJliste");
aJliste.setBaseStyle("AJnormal");
//font
// paragraph
aJliste.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
//set the first line indent to -.63 cm
aJliste.getParagraphFormat().setFirstLineIndent((-0.63*567)/20);
//tabulation
List list1 = doc.getLists().add(ListTemplate.BULLET\_SQUARE);
list1.getListLevels().get(0).setLinkedStyle(aJliste);
list1.getListLevels().get(0).setTabPosition((0.63*567)/20);
aJliste.getListFormat().setList(list1);
aJliste.getParagraphFormat().setLeftIndent(0);
To build it, I use this very simple code I got from your website:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Modify the first section in the document.
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
builder.getPageSetup().setPaperSize(PaperSize.A4);
//builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
builder.getPageSetup().setLeftMargin((2.5*567)/20);
builder.getPageSetup().setRightMargin((2.5*567)/20);
builder.getPageSetup().setTopMargin((2.5*567)/20);
builder.getPageSetup().setBottomMargin((2.5*567)/20);
builder.getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
builder.getParagraphFormat().setStyleName(aJliste.getName());
builder.write("AJliste");
doc.save(".\Sortie\generated.doc");
The generated document is also attached.
The problem is that this code generates then a style with a leftIndent of -.63 instead of 0.
It seems to me that the problem comes when you set a negative FirstLineIndent. Whenever I set one, the value of the leftIndent is always equals to its original value plus the negative FirstLineIndent.
For exemple, if the leftIndent is 4cm and that i want to add a negative FirstLineIndent of 1.2cm, the leftIndent will 2.8 cm.
This problem doesn’t occur when the FirstLineIndent is positive.
Also, I couldn’t find how to set the LineSpacingRule to “Simple”, “Double” and “1.5 lines” since the setLineSpacingRule() method only provides the other choices.
I found a way to get an almost exactly problem despite the problem with the negative first line indent. Here is the code :
Style aJliste = doc.getStyles().add(StyleType.PARAGRAPH, "AJliste");
aJliste.setBaseStyle("AJnormal");
// paragraph
aJliste.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
aJliste.getParagraphFormat().setFirstLineIndent(-17.85);
// list
List list = doc.getLists().add(ListTemplate.BULLET\_SQUARE);
ListLevels listLevels = list.getListLevels();
for (int i = 0; i < listLevels.getCount(); i++) {
ListLevel listLevel = listLevels.get(i);
listLevel.setRestartAfterLevel(0);
listLevel.setLinkedStyle(aJliste);
listLevel.setNumberStyle(NumberStyle.BULLET);
listLevel.setNumberPosition(0);
listLevel.setTabPosition(17.85);
listLevel.setTextPosition(17.85);
listLevel.isRestartAfterHigher(true);
listLevel.setRestartAfterLevel(0);
}
aJliste.getListFormat().setList(list);
aJliste.getListFormat().setListLevelNumber(0);
The problem is that this generate a list with 9 levels and I only need one.
The setListLevelNumber(0) doesn’t change that.
Moreover, as you can see in the generated document attached, each bullet cannot be indented seperately. Only the first bullet can be indented but it indents then the other bullets.
Is there any way first to remove all the listLevel but the first and “unlink” them?
thank you.
thank you.
I also need to know how to generate a paragraph style list of one level instead of 9.
What I’m doing right now is use a ListTemplate.BULLET_SQUARE and modify it but it has 9 levels.
And I need each bullet to be independant from the previous like in the AJListe document attached in the previous post so that when you increase the indent, the other bullets don’t move.
Please note that the value that is shown in MS Word’s Paragraph dialog in Indents and Spacing | Indentation | Before text is actually a sum of LeftIndent and FirstLineIndent values of Aspose.Words API. That is by design. Aspose.Words tends more to reflect values that are stored in the document binary then how they are shown in MS Word.
Lists can actually be of several types: simple, multilevel and hybrid. Standard styles are mostly multilevel. I am not sure if creation of simple lists is possible with Aspose.Words public API. Please give me some time to check this with other team members.
I would like to ask just out of curiosity - why are you trying to create styles in code. Wouldn’t it be much simplier to create a template document and define all styles there using MS Word?
Concerning ‘independent’ bullets, I don’t quite understand what do you mean here. In the attached document bullets can be moved independently using the ruler in MS Word. Try to give an example using sample documents created in MS Word and Aspose.Words and pointing out the difference in behavior between them.