Aspose Word aligning text after astrix and removing first character if first line is entirely white spaces

Hi. We found two issues -

  1. If there is are spaces followed by an astrix followed by text, Aspose Words aligns the text after the astrix.
  2. If the first line is entirely white spaces, Aspose Words removes the first character of the text.

Could you please advise.

@gs01 Unfortunately, the problem is not quite clear. Could you please attach your input, output and expected output documents along with code that will allow us to reproduce the problem on our side? We will check the issue and provide you more information.

So there are two code snippets as below -

Document main = new Document();
...
LoadOptions loadOptions = new LoadOptions(LoadFormat.TEXT, null, null);
String text = "                                                                              This is a test.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8);
Document documentToAppend = new Document(inputStream, loadOptions));

main.appendDocument(documentToAppend, ImportFormatMode.KEEP_SOURCE_FORMATTING);

… and …

Document main = new Document();
...
LoadOptions loadOptions = new LoadOptions(LoadFormat.TEXT, null, null);
String text = "                                           * This is a test. This is a test. This is a test. This is a test. This is a test.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8);
Document documentToAppend = new Document(inputStream, loadOptions));

main.appendDocument(documentToAppend, ImportFormatMode.KEEP_SOURCE_FORMATTING);

and these produce the attached two buggy PDFs attached respectively.
missing_character.pdf (11.8 KB)

asterix.pdf (12.1 KB)

@gs01 Thank you for additional information.

  1. The character is not missed. The fist character is on the previous line of text. This occurs because by default leading whitespaces are converted to paragraph first line indent. You can control this behavior by specifying TxtLoadOptions.LeadingSpacesOptions. Please try modifying your code like this:
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setLeadingSpacesOptions(TxtLeadingSpacesOptions.PRESERVE);
String text = "                                                                              This is a test.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
Document doc = new Document(inputStream, loadOptions);
doc.save("C:\\Temp\\out.pdf");
  1. Lines with leading asterixis are detected as list items by default, you can disable this by specifying TxtLoadOptions.AutoNumberingDetection. Please see the following code:
TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setLeadingSpacesOptions(TxtLeadingSpacesOptions.PRESERVE);
loadOptions.setAutoNumberingDetection(false);
String text = "                                           * This is a test. This is a test. This is a test. This is a test. This is a test.";
ByteArrayInputStream inputStream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
Document doc = new Document(inputStream, loadOptions);
doc.save("C:\\Temp\\out.pdf");

The missing character is still an issue - I had just not put enough spaces. I am able to reproduce it now (just by adding a few more spaces) and have attached the PDF.
missing_character.pdf (11.7 KB)

@gs01 As I have mentioned this occurs because leading whitespaces are converted to the first line indent. Just use the following load options to preserve leading whitespaces as whitespaces:

TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.setLeadingSpacesOptions(TxtLeadingSpacesOptions.PRESERVE);

out.pdf (12.6 KB)