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écie é muito dada a clãs sólidos... pelo que só estabelece relações com espécies da mesma família... exceptuando-se as presas com as quais tem relações dificeis e por vezes letais</em></strong><strong><em>Esta espécieé muito dada a clãs sólidos... pelo que só estabelece relações com espécies da mesma família... exceptuando-se as presas com as quais tem relações dificeis e por vezes letais</em></strong>
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écie é muito dada a clãs sólidos... pelo que só estabelece relações com espécies da mesma família... exceptuando-se as presas com as quais tem relações dificeis e por vezes letais</em></strong><strong><em>Esta espécieé muito dada a clãs sólidos... pelo que só estabelece relações com espécies da mesma família... exceptuando-se as presas com as quais tem relaçõ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.
}
}
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.
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!
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.