@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.
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)
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");
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);