Txt to PDF conversion issues

Hi, I am trying to convert a txt file to pdf format according to: https://forum.aspose.com/t/convert-text-to-pdf/37071
In the converted pdf file, the lines break not as they break in the text file. I suppose there is a configuration that should change the maximum row length but I couldn’t find such an option.
files.zip (64.1 KB)

I have also tried the option that written in https://github.com/aspose-pdf/aspose.pdf-for-java
and got a bad result:
output1.pdf (36.8 KB)

I would like to get help to find the right and best way to convert txt to pdf file.

@ghaj17,

Please ZIP and upload your input Text file here for testing. Please also provide a comparison screenshot highlighting the problematic areas in Aspose.Words generated PDF file and attach it here for our reference. Please point out the exact problematic places for this issue. We will then investigate the issue on our end and provide you more information.

Please see the attached zip files that contains that input, output and also some highlights (as png files). filesAndHighlights.zip (144.0 KB)

The second method of conversion as I write before was bad, this is the result: output1.pdf (36.8 KB)

@ghaj17,

Even MS Word 2019 will cause the same problem if you open this .txt file with MS Word 2019 and then ‘Save As’ to PDF. However, you can fix this issue by reducing the Left and Right Page margins by using the following Aspose.Words’ code:

.NET

Document doc = new Document(@"E:\filesAndHighlights\input.txt");

PageSetup ps = doc.FirstSection.PageSetup;
ps.LeftMargin = 0.36 * 72; // 0.5 inch
ps.RightMargin = 0.36 * 72;
            
doc.Save(@"E:\filesAndHighlights\19.8.pdf"); 

Java:

Document doc = new Document("E:\\filesAndHighlights\\input.txt");

PageSetup ps = doc.getFirstSection().getPageSetup();
ps.setLeftMargin(0.36 * 72); // 0.5 inch
ps.setRightMargin(0.36 * 72);

doc.save("E:\\filesAndHighlights\\awjava-19.7.pdf");

Attachment: 19.8.pdf (30.0 KB)

Thanks, I hope this configuration will be good for additional text files that I will convert to pdf.

@ghaj17,

Aspose.Words tries to mimic the behavior of MS Word. Please let us know if you have any troubles in future and we will be glad to look into this further for you in case where Aspose.Words’ behavior differs to what MS Word produces.