TXT to PDF issue (text position on page)

Hello,

I have new report for you today.

It seems, that text position on output PDF file page is not the same as in the source TXT file I can see in Notepad or if I open this TXT file in MS Word.

Please look an attached ZIP file to see the source TXT, output PDF and the screenshot image.
_page sizes test.zip (228.0 KB)

My code snippet is below.

Mikhael

Dim sSrcFile = "C:\Users\email\Desktop\_page sizes test\LSI_M50095_08102024_PinningChartOut_07102024112538_1 (TXT).txt"
Dim sOutPDF = "C:\Out\Aspose.Words output.pdf"

Dim wordDoc As New Aspose.Words.Document(sSrcFile)

For Each sec As Section In wordDoc.Sections
    sec.PageSetup.LeftMargin = 0
    sec.PageSetup.RightMargin = 0
    sec.PageSetup.TopMargin = 0
    sec.PageSetup.BottomMargin = 0
Next

Dim soPDF As Aspose.Words.Saving.PdfSaveOptions = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Pdf)
wordDoc.Save(sOutPDF, soPDF)

@Mikhael The problem occurs becasue by default upon loading TXT document leading spaces are converted to indents. To get the expected output you should preserve leading spaces:

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

Document doc = new Document(@"C:\Temp\in.txt", opt);
doc.Save(@"C:\Temp\out.pdf");

Hello @alexey.noskov ,

Wow! Thank you for your advice!

Mikhael

1 Like