Mail Merge Fields - Raw HTML in Database vs Real end format

Hello,
I’m using Aspose.Words to generate a report in PDF format, but I’ve a problem using the raw HTML stored in my Oracle database.The problem is that I need to see the real format os the text instead of the raw HTML, how can I do that??
This is just a sample of what I’m getting right now:

<strong><em>Esta esp&eacute;cie &eacute; muito dada a cl&atilde;s s&oacute;lidos... pelo que s&oacute; estabelece rela&ccedil;&otilde;es com esp&eacute;cies da mesma fam&iacute;lia... exceptuando-se as presas com as quais tem rela&ccedil;&otilde;es dificeis e por vezes letais</em></strong><strong><em>Esta esp&eacute;cie&eacute; muito dada a cl&atilde;s s&oacute;lidos... pelo que s&oacute; estabelece rela&ccedil;&otilde;es com esp&eacute;cies da mesma fam&iacute;lia... exceptuando-se as presas com as quais tem rela&ccedil;&otilde;es dificeis e por vezes letais</em></strong>

Hi
Abel,

Thanks for your inquiry. Please try using the following code snippet:

Document doc = new Document(@"C:\test\in.docx");
string html = "<strong><em>Esta esp&eacute;cie &eacute; muito dada a cl&atilde;s s&oacute;lidos... pelo que s&oacute; estabelece rela&ccedil;&otilde;es com esp&eacute;cies da mesma fam&iacute;lia... exceptuando-se as presas com as quais tem rela&ccedil;&otilde;es dificeis e por vezes letais</em></strong><strong><em>Esta esp&eacute;cie&eacute; muito dada a cl&atilde;s s&oacute;lidos... pelo que s&oacute; estabelece rela&ccedil;&otilde;es com esp&eacute;cies da mesma fam&iacute;lia... exceptuando-se as presas com as quais tem rela&ccedil;&otilde;es dificeis e por vezes letais</em></strong>";

doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
doc.MailMerge.Execute(new string[]
{
    "html"
}, new object[]
{
    html
});
doc.Save(@"C:\test\out.docx");
private class HandleMergeFieldInsertHtml: IFieldMergingCallback
{
    ///
    /// This is called when merge field is actually merged with data in the document.
    ///
    void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
    {
        // All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'.
        if (e.DocumentFieldName.StartsWith("html"))
        {
            // Insert the text for this merge field as HTML data, using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder(e.Document);
            builder.MoveToMergeField(e.DocumentFieldName);
            builder.InsertHtml((string) e.FieldValue);
            // The HTML text itself should not be inserted.
            // We have already inserted it as an HTML.
            e.Text = "";
        }
    }
    void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
    {
        // Do nothing.
    }
}

I hope, this will help.

Best Regards,

Hi, thanks for the reply,

but, I’m using this

'GetData returns a DataSet
doc_Renamed.MailMerge.ExecuteWithRegions(GetData(idDoc, tipo))

and only a few items os the dataset are html,

is there any other way to solve this?

Thanks again,

Hi
Abel,

Thanks for the additional information. I suppose, you should write your own custom code to be able to detect if the incoming field data from your data source should be inserted into document as a HTML fragment or not. You can also mark all merge fields that expect HTML data with some prefix, e.g. ‘html’. If we can help you with anything else, please feel free to ask.

Best Regards,

Thanks, that solved my problem!
I know what specific fields I’ve in HTML, so I’ve specified them in a List and fired the callback function just for that cases!
Best Regards!

Hi Abel,

Thanks for your inquiry. It is perfect that you managed to achieve what you were looking for. In case you have any further inquires or need any help, please let us know.

Best Regards,