On downloading text document all left aligned spaces got removed

I am working on text document and when creating document using input stream all left spaces of doc got removed pls suggest…
below code I am using…

public AsposeWordDocument(InputStream documentInputStream, String name) throws AsposeException {
    this.name = name;
    try {
        this.document = new Document(documentInputStream);
        document.joinRunsWithSameFormatting();
        documentBuilder = new DocumentBuilder(document);
        LOG.debug(name + " has " + document.getPageCount() + " pages");
    } catch (Exception ex) {
        throw new AsposeException(ex);
    }
}

@shivp Could you please attach your input output and expected output documents here for our reference? We will check the issue and provide you more information.

Input: input-output sample.zip (1.9 KB)

zip contains input and output sample files expected output should be same as input.

we are saving input file the DB in varbinary(max) format and at the time of download we convert it to byte array and creating aspose Document from same stream and alignment got changed.

@shivp By default upon loading TXT document leading spaces are converted to indents. You can control this behavior by specifying the appropriate property in TxtLoadOptions:

TxtLoadOptions options = new TxtLoadOptions();
options.setTrailingSpacesOptions(TxtTrailingSpacesOptions.PRESERVE);
options.setLeadingSpacesOptions(TxtLeadingSpacesOptions.PRESERVE);
Document doc = new Document("C:\\Temp\\Input sample.txt", options);
doc.save("C:\\Temp\\out.txt");

thanks alexey

I am using below version and can’t see these class TxtLoadOptions.
com.aspose
words
16.11.0

please let me know which one stable version I should use?

@shivp Unfortunately, the mentioned options are not available in 16.11 version of Aspose.Words. They were introduced in 18.7 version:
https://docs.aspose.com/words/java/aspose-words-for-java-18-7-release-notes/#txtloadoptions-class-was-extended

So I would suggest you to update your version of Aspose.Words.

1 Like

is this available for free?
please ping me maven dependancy

@shivp Every Aspose license provides a 1-year subscription for free upgrades to any new Aspose.Words version that comes out. Any Aspose.Words version released before the subscription expiry date - you can just download and use it.

If you want to check when your subscription expires, open the license file in Notepad (but take care not to modify and save the license file or it will no longer work) and see the SubscriptionExpiry field.

<SubscriptionExpiry>20220218</SubscriptionExpiry>

It means that you can free upgrade to version of Aspose.Words published before 02/18/2022.

You can get Aspose.Words for Java from our maven repository:
https://repository.aspose.com/words/

A post was split to a new topic: Issues while applying license