Random Space and Tab is added or missing after upgrading Aspose words from 21 to 23.1 (Aspose words for JAVA)

Hi, I recently updated the Aspose words library from 21.2 to 23.1 to make it compatible with JAVA 17. It does not give any issues but when I am creating a document with it, The generated document somehow contains space, tab between text, paragraphs, and bullets. PFA SS for the same.
After update_Document_aspose_words_23.1v

Original_Document_aspose_words_21v

Code Snipet

NOTE: It was working fine with 21v.

@wivo Could you please attach your input, output and expected output documents here for testing? We will check the issue and provide you more information. Unfortunately, it is impossible to analyze the issue using screenshots.

Sure, Here I am attaching both documents (expected and actual)
Actual Document.docx (11.2 KB)

Expected document.docx (15.2 KB)

@wivo Thank you for additional information. But could you please also provide code and inputs you use to generate the Actual Document.docx? This will help us better understand your scenario and help appropriately.

@alexey.noskov, I haven’t made any code changes, just updated the Aspose words version, Anyhow here is the code snippet which I think might cause the issue.

fun insertTextAndLineInMargin(doc: Document, text: String) {
    val shapes = doc.getChildNodes<Shape>().toMutableList()
    val shape = shapes.find { it.alternativeText == LEFT_MARGIN_TEXT }
    if (shape != null) {
        // If textbox is already present, simply replace its text
        shape.firstParagraph.removeAllChildren()
        val run = Run(doc)
        run.text = text
        shape.firstParagraph.appendChild(run)
    } else {
        val pageSetup = doc.firstSection.pageSetup

        // Add textbox shape in left margin of document
        val textBox = Shape(doc, ShapeType.TEXT_BOX)
        textBox.wrapType = com.aspose.words.WrapType.NONE
        // Left portion of textbox should be set at 30% of left margin of page
        textBox.left = pageSetup.leftMargin * 0.3
        textBox.height = 10.0
        // Width of textbox should be set at 70% of left margin of page
        textBox.width = pageSetup.leftMargin * 0.7
        textBox.top = pageSetup.topMargin
        textBox.textBox.fitShapeToText = true
        textBox.stroked = false
        textBox.relativeHorizontalPosition = RelativeHorizontalPosition.PAGE
        textBox.relativeVerticalPosition = RelativeVerticalPosition.PAGE
        textBox.verticalAlignment = VerticalAlignment.INLINE
        // Set alternative text to identify shape
        textBox.alternativeText = LEFT_MARGIN_TEXT
        textBox.appendChild(Paragraph(doc))
        val paragraph = textBox.firstParagraph
        paragraph.paragraphFormat.alignment = ParagraphAlignment.LEFT
        val run = Run(doc)
        run.text = text
        paragraph.appendChild(run)
        doc.firstSection.body.firstParagraph.appendChild(textBox)

        // Add Line shape after textbox
        val textboxHeight = textBox.shapeRenderer.sizeInPoints.y
        val line = Shape(doc, ShapeType.LINE)
        line.stroke.dashStyle = DashStyle.SOLID
        line.wrapType = com.aspose.words.WrapType.NONE
        // Width of line should be set at 50% of left margin of page
        line.width = pageSetup.leftMargin * 0.5
        line.top = textboxHeight.toDouble() + pageSetup.topMargin + 14.0
        // Left portion of line should be set at 30% of left margin of page plus 8.0 points
        line.left = (pageSetup.leftMargin * 0.3) + 8.0
        line.relativeHorizontalPosition = RelativeHorizontalPosition.PAGE
        line.relativeVerticalPosition = RelativeVerticalPosition.PAGE
        line.verticalAlignment = VerticalAlignment.INLINE
        line.alternativeText = LEFT_MARGIN_LINE
        doc.firstSection.body.firstParagraph.appendChild(line)
    }
}

@wivo Thank you for additional information, but please provide also input document and input string passed to the provided method to generate the problematic output.

Hi @alexey.noskov, I have found the issue. It was with LayoutEnumerator. My custom formats applied to the document were reset when I was using the LayoutEnumerator. Can you please briefly inform me what the new change made in v23.1 for the LayoutEnumerator class as it was not creating any issues with v21.2?

LayoutEnumerator(doc)

@wivo When LayoutEnumerator is created in the code, Aspose.Words builds document layout. This is quite complex process. There were 24 releases between 23.1 and 21.1 version of Aspose.Words and each of the releases had about 80 fixed and improvements, big part of which have been made in Aspose.Words layout module. So it is difficult briefly describe changes made in Aspose.Words layout engine made after 21.1 version.

It would be great if you create a simple application that will allow us to reproduce the problem. We will check it and provide you more information.

Hi @alexey.noskov, I’ve attached a Zip file with all the data to reproduce this issue.

PDF Text Issue.zip (8.8 MB)

@wivo Unfortunately, it is still not clear what the problem is. Could you please check whether the problem is reproducible on your side after simple DOC to PDF conversion? As I can see the produced PDF document looks fine.

@alexey.noskov, We’ve successfully resolved the issue at our end. However, as we proceed with upgrading Aspose for JAVA from version 21.2 to 23.1, a few additional challenges have surfaced. I’ll be posting these on the forum shortly for further assistance.

Thank you immensely for your continuous support!

1 Like

@wivo It is perfect that you managed to find the reason of the problem. Please feel free to ask in can of any other issues, we will be glad to help you.