We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Text .txt File to PDF Format Conversion using C# .NET | Leading Space Handling during Loading Plain Text

PDF file contains broken (displaced or cut) text after conversion from TXT in comparison with original document.

Input TXT file:http://documents1.worldbank.org/curated/en/996911467995898452/text/103281-WP-P132922-Box394864B-PUBLIC-poverty-and-welfare-021216-final.txt
Example output:
image.png (8.5 KB)

Version: Aspose.Slides.NET 20.9.0


We have logged this problem in our issue tracking system with ID WORDSNET-21165. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


Regarding WORDSNET-21165, the problematic line of text contains 107 leading spaces. Aspose.Words tries to remove them and convert to left indent by default. The average character width is taken about 6pt, so the left indent of first line is set to 13484 twips. As page width is set to 12240 twips by default, the first line of problematic paragraph is started out of the page bounds and the text is looking as displaced or cut.

We probably could introduce some scaling to solve the problem. Perhaps we should set page width wider than longest line of the text or may be shrink indents of the paragraphs to fit on the page.

However, the Aspose.Words behavior for leading spaces can be adjusted with TxtLoadOptions.LeadingSpacesOptions option. To mimic MS Word’s behavior, please set it as the following:

TxtLoadOptions loadOptions = new TxtLoadOptions();
loadOptions.LeadingSpacesOptions = TxtLeadingSpacesOptions.Preserve;

Document doc = new Document("C:\\temp\\103281-WP-P132922-Box394864B-PUBLIC-poverty-and-welfare-021216-final.txt", loadOptions);

If that does not produce expected results on your end then please provide us a document that shows your expected output. We will then investigate the scenario further on our end and provide you more information.