We are facing very critical issue, when we upgrading the Aspose.Words “19.10” to the latest version.
After we merge the data in word document template and save as pdf, the data-bound fields shows data without html rendering. Previously it is showing fine. Normal data without html tags working good.
Please see the attached program file to execute it and also attached sample template and merge data file. Review the final output document (before and after upgrade).
using (var docStream = new MemoryStream())
{
// load word document template
byte[] template = File.ReadAllBytes("MergeDataTemplate.docx");
docStream.Write(template, 0, template.Length);
using (var pkg = Package.Open(docStream, FileMode.Open, FileAccess.ReadWrite))
{
using (var wordDoc = WordprocessingDocument.Open(pkg))
{
// load merge data for word document
string mergeDataXml = File.ReadAllText("MergeData.xml");
var mergeDataDoc = new XmlDocument();
mergeDataDoc.LoadXml(mergeDataXml);
// set merge data to word document template
...
// merge data in word document template
...
// save the word document template
wordDoc.MainDocumentPart.Document.Save();
wordDoc.Close();
}
}
docStream.Seek(0, SeekOrigin.Begin);
// save the word template to pdf
using (var pdfStream = new MemoryStream())
{
var saveOptions = (PdfSaveOptions)SaveOptions.CreateSaveOptions(SaveFormat.Pdf);
saveOptions.FontEmbeddingMode = PdfFontEmbeddingMode.EmbedNonstandard;
saveOptions.ImageCompression = PdfImageCompression.Jpeg;
saveOptions.JpegQuality = 90;
var document = new Document(docStream);
document.Save(pdfStream, saveOptions);
pdfStream.Seek(0, SeekOrigin.Begin);
using (var fileStream = File.OpenWrite("FinalDocument.pdf"))
{
pdfStream.Seek(0, SeekOrigin.Begin);
pdfStream.CopyTo(fileStream);
}
}
}
See attached file for the whole program.
FinalDocument_ACTUAL.pdf (39.4 KB)
FinalDocument_EXPECTED.pdf (67.8 KB)
MergeDataTemplate.docx (24.2 KB)
MergeData.xml.zip (1.1 KB)
Program.cs.zip (1.5 KB)