Aspose swaps the order of paragraphs in input fields when exporting to PDF with the "PreserveFormFields" option enabled

When text is entered in a form field that is separated by blank lines, the blank lines are moved to the end of the text during PDF export with the “PreserveFormFields” option enabled. If the “PreserveFormFields” option is disabled, the order remains unchanged.

Aspose.Words-Version: 24.7.0

using System.Diagnostics;
using Aspose.Words;
using Aspose.Words.Fields;
using Aspose.Words.Saving;
using MoreLinq;

const string templatePath = @"path\to\form-test.docx";
const string outputPath = @"output\path\form-test.pdf";

Document document;
using (FileStream stream = File.Open(templatePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
    document = new Document(stream);
}

FormFieldCollection formsFields = document.Range.FormFields;
formsFields.ForEach(formField => {
    formField.Enabled = false;
});

PdfSaveOptions saveOptions = new() {
    Compliance = PdfCompliance.Pdf20,
    PreserveFormFields = true
};

document.Save(outputPath, saveOptions);

ProcessStartInfo startInfo = new() {
    FileName = outputPath,
    UseShellExecute = true
};
Process.Start(startInfo);

Template: template.zip (9.3 KB)

@kvaak
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-27183

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like