Hello,
I m trying to send html format in my placeholder and then generate a pdf and it s working as expected .
Now i want that what i send in html will be formated with the right size and format policy of the appropriate placeholder in my template .
I need your help please!
Don’t hesitate if you node more clarifications !
Thanks in advance.
Yes that’s the part of code that we implement when we insert html tags
public void fieldMerging(FieldMergingArgs args) throws Exception {
if (documentBuilder == null){
documentBuilder = new DocumentBuilder(args.getDocument());
}
// ------ HTML Handling --------
// All merge fields that expect HTML data should be marked with some prefix, e.g. 'html'
if (args.getDocumentFieldName().startsWith(HTML_PREFIX) && args.getFieldValue() != null) {
// Insert the text for this merge field as HTML data, using DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(args.getDocument());
builder.moveToMergeField(args.getDocumentFieldName());
builder.insertHtml((String) args.getFieldValue());
}
Today we generate a right pdf when we push html in fieldValue like this :
{
"fieldName": "HTML_MAIN_TEXT_BODY",
"fieldValue": "<div style='color: black; font-family: Times New Roman; font-size: 12px'><u>Special Condition(s)</u><br/> The Euler Hermes grade that you have requested for the above mentioned company is 06, USD 40 000. It may also be consulted via our online portal.<br/>Please note that if at any time during the duration of this EZ Cover decision, we issue you a <b>Permitted limit</b> on the Insured Buyer, the <b>Permitted limit</b> takes precedence over this EZ Cover decision.</div>",
"typeCode": "HTML"
}
But now my objectif is not to set manually the policy in the style of balise html , but i want to set it in the code when i insertHtml (means that want to insert html with the font size that i have in the placeholder (MAIN_TEXT_BODY) mentionned in my document ) and send it to Aspose .
Thanks!
I have this code as fillPlaceholder :
public Document fillPlaceholders(TemplateDataSourceDto dataSource, Document template) {
1 LOGGER.info(“Fill placeholders”);
2 // register listener for warning events generated by aspose document processor
3 template.setWarningCallback(new HandleDocumentWarnings());
4 // remove placeholders name when the field is unused
5 template.getMailMerge().setCleanupOptions(REMOVE_UNUSED_REGIONS | REMOVE_UNUSED_FIELDS | REMOVE_EMPTY_PARAGRAPHS);
// merge specific fields like booleans or html
6 // here to insert
7 template.getMailMerge().setFieldMergingCallback(new HandleMergeField());
If i add this : template.setAutomaticallyUpdateStyles(true); to the line 6 it will fix the issue ?