Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Tue Feb 07, 2023 12:37 am

Hello
please look when multi-string mergefield has wrong format in pdf, but correct in docx
using latest version of Spire.Office Platinum (8.1.4)


private void button30_Click(object sender, EventArgs e)
{

Document SPD = new Document("D:\\PassTemplate.docx");
string[] fieldNames = SPD.MailMerge.GetMergeFieldNames().Distinct().ToArray();
string[] fieldValues = (string[])fieldNames.Clone();

SPD.MailMerge.MergeField += MailMerge_MergeField;


SPD.MailMerge.Execute(fieldNames, fieldValues);
SPD.SaveToFile("D:\\12.pdf", Spire.Doc.FileFormat.PDF);
SPD.SaveToFile("D:\\12.docx", Spire.Doc.FileFormat.Docx);
}

private void MailMerge_MergeField(object sender, MergeFieldEventArgs args)
{
if ("pass_Note,".Contains(args.FieldName + ","))
{
args.Text = "Vehicle Year* : 2022\nVehicle Make* : InTech\nVehicle Model * : Terra Oasis Rover\nVehicle Color* : White\nVehicle License Plate Number* : AAAAAA\nPass Start Date* : 1/20/2023\nPass End Date* : 1/21/2023";

}
}

sserra
 
Posts: 76
Joined: Tue Jun 13, 2017 4:03 pm

Tue Feb 07, 2023 6:56 am

Hi,

Thanks for your feedback.
Please use " \r\n" for carriage return and line feed. I replaced all your “\r” with “\r\n” and did a test, the format was correct in both Word document and PDF document, see attached picture.
test.png

You can try our suggestion, if your issue still exists or you have further questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc

cron