Text position change in linux box while converting docx to PDF


We are facing issue in Linux while converting docx to PDF.

PrefillDemo_IntakeForm_v4.docx (60.8 KB) is docx file which we are trying to convert to PDF.

Actual.pdf (39.3 KB) we are getting this file as output but expectation is
Expected.pdf (119.2 KB) where Age word is getting expand to next line.

We are using below code,

string FilePath = Directory.GetCurrentDirectory() + "/PrefillDemo_IntakeForm_v4.docx";
using FileStream fs = File.OpenRead(FilePath);
Aspose.Words.Document document = new Aspose.Words.Document(fs);
using (var dstStream = new MemoryStream())

    Aspose.Words.Fonts.FontSettings.DefaultInstance.SetFontsFolder("/usr/share/fonts", true);
    document.Save(dstStream, Aspose.Words.SaveFormat.Pdf);
    dstStream.Position = 0;
    var b = new byte[dstStream.Length];
    dstStream.Read(b, 0, b.Length);
    dstStream.Position = 0;
    DirectoryInfo info = new DirectoryInfo(Directory.GetCurrentDirectory());
    string path = Path.Combine(Directory.GetCurrentDirectory(), "Converted.pdf");
    using (FileStream outputFileStream = new FileStream(path, FileMode.Create))

We are getting expected file on windows but on Linux, word break into next line.

Please let us know what need to do to fix this issue.

@jsign can you please reattach the Actual and Expected documents (the link is broken), please zip both files and upload it?

Result.zip (149.0 KB)
This zip contains both files, actual and expected.

1 Like

@jsign sorry I cannot reproduce your issue, I’m using the version 23.2.0 of the Aspose.Words package, this is the code that I’m using:

Document doc = new Document("C:\\Temp\\input.docx");
PdfSaveOptions opt = new PdfSaveOptions()
    PreserveFormFields = true

doc.Save("C:\\Temp\\output.pdf", opt);

I test with and without the Aspose.Words lisence and I got the same result.
output.pdf (93.1 KB)

@jsign In your actual and expected output document different fonts are used. The problem might occur because the fonts used in your input document are not available on the machine where document is converted to PDF. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to lean where Aspose.Words looks for fonts:

FYI @eduardo.canal