Define the line spacing on com.aspose.words.Document

In our project we work with Jasper to create templates and then export them as word or pdf.
When we export the Word document we try to insert images but the size is trucated vertically and they re not properly displayed , I tried to add linespacing and adjust the height but it doesn’t work

<band height="20" splitType="Stretch">
	<textField textAdjust="StretchHeight" evaluationTime="Page" isBlankWhenNull="true">
		<reportElement style="texte" stretchType="RelativeToTallestObject" x="0" y="0" width="467" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF" uuid="d85e42a3-ec3b-4509-b7c9-51b9a3e56cc5">
			<printWhenExpression><![CDATA[!$F{textCenter1}.isEmpty()]]></printWhenExpression>
		</reportElement>
		<textElement textAlignment="Center" markup="styled">
			<paragraph lineSpacing="AtLeast" lineSpacingSize="1.0"/>
		</textElement>
		<textFieldExpression><![CDATA[$F{textCenter1}]]></textFieldExpression>
	</textField>
	<textField textAdjust="StretchHeight" isBlankWhenNull="true">
		<reportElement style="texte" stretchType="RelativeToTallestObject" x="0" y="0" width="467" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF" uuid="afa0f58f-3700-44a0-bebc-4c3ad6d28efd">
			<printWhenExpression><![CDATA[!$F{textLeft1}.isEmpty()]]></printWhenExpression>
		</reportElement>
		<textElement textAlignment="Left" markup="styled"/>
		<textFieldExpression><![CDATA[$F{textLeft1}]]></textFieldExpression>
	</textField>
	<textField textAdjust="StretchHeight" isBlankWhenNull="true">
		<reportElement style="texte" stretchType="RelativeToTallestObject" x="0" y="0" width="467" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF" uuid="7b207948-a94b-4da1-b3fe-a1beb8123070">
			<printWhenExpression><![CDATA[!$F{textRight1}.isEmpty()]]></printWhenExpression>
		</reportElement>
		<textElement textAlignment="Right" markup="styled"/>
		<textFieldExpression><![CDATA[$F{textRight1}]]></textFieldExpression>
	</textField>
	<textField textAdjust="StretchHeight" isBlankWhenNull="true">
		<reportElement style="texte" stretchType="RelativeToTallestObject" x="0" y="0" width="467" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF" uuid="d0c3c8d5-ce81-48ad-bf1b-49f42ac0bd2a">
			<printWhenExpression><![CDATA[!$F{textJustified1}.isEmpty()]]></printWhenExpression>
		</reportElement>
		<textElement textAlignment="Justified" verticalAlignment="Top" markup="styled">
			<paragraph lineSpacing="AtLeast" lineSpacingSize="1.0"/>
		</textElement>
		<textFieldExpression><![CDATA[$F{textJustified1}]]></textFieldExpression>
	</textField>
</band>

Is there a way to fix this java side when creating the document ?

@Mouna87 Could you please attach your output and expected output documents? Do you insert images using Aspose.Words for Java? If so please attach also input MS Word document here for our reference and code you use to insert the image.

I am trying to insert the image manually after the export
image.jpg (86.9 KB)

Hello I put an example of an image I want to insert on my word document
and this is how it is displayed on the word

I tried this code that you gave as a response on another question but it doesn’t work

// sauvegarde en DOCX
com.aspose.words.LoadOptions lo = new com.aspose.words.LoadOptions();
lo.setLoadFormat(com.aspose.words.LoadFormat.DOCX);
com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(baos.toByteArray()), lo);
DocumentBuilder builder = new DocumentBuilder(doc);


// And another paragraph with LineSpacingRule.MULTIPLE
builder.getParagraphFormat().setLineSpacingRule(LineSpacingRule.MULTIPLE);
builder.getParagraphFormat().setLineSpacing(12);
//ici on  va mettre la langue française par defaut
doc.getStyles().getDefaultFont().setLocaleId(1036);
doc.getStyles().getDefaultParagraphFormat();
// ajout marges (par défaut, la marge de droite n'est pas prise en
// compte d'où la méthode)
doc = ajouterMargesWord(jasperPrint, doc);

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
doc.save(outStream, SaveFormat.DOCX);

@Mouna87 Could you please attach you input MS Word document, i.e. the document loaded at this line:

com.aspose.words.Document doc = new com.aspose.words.Document(new ByteArrayInputStream(baos.toByteArray()), lo);

and output document produced by the provided code.

Hello,

I don’t know which information about the output do you need ?
On debug I have these :

@Mouna87 I mean your input MS Word document and output MS Word document in DOCX or other MS Word format. it is difficult to analyze the issue using screenshots.

Hello,

I don’t know which information about the output do you need ?
On debug I have these :
Uploading: image.png…

image.png (30.3 KB)

this is the output document
28507244_1708939384926.docx (27.4 KB)

The input we re based on Jasper templates

Is there a way to change linespacing from the java code
image.png (138.1 KB)

@Mouna87 Please use the following code:

Document doc = new Document("C:\\Temp\\in.docx");
        
for(Paragraph p : (Iterable<Paragraph>)doc.getChildNodes(NodeType.PARAGRAPH, true))
    p.getParagraphFormat().setLineSpacing(LineSpacingRule.AT_LEAST);
        
doc.save("C:\\Temp\\out.docx");

Thanks Alexey,
I did as the following

for(com.aspose.words.Paragraph p : (Iterable<com.aspose.words.Paragraph>)doc.getChildNodes(NodeType.PARAGRAPH, true)) {
	p.getParagraphFormat().setLineSpacingRule(LineSpacingRule.AT_LEAST);
	p.getParagraphFormat().setLineSpacing(1);
}

and it worked perfectly

@Mouna87 It is perfect that you managed to resolve the problem. Please feel free to ask in case of any issues, we will be glad to help you.