<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oliver</title>
    <description>The latest articles on DEV Community by Oliver (@gialoui).</description>
    <link>https://dev.to/gialoui</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F155153%2Fa94c0c97-0804-4469-842a-12f8dff14610.png</url>
      <title>DEV Community: Oliver</title>
      <link>https://dev.to/gialoui</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gialoui"/>
    <language>en</language>
    <item>
      <title>Style not remain (including font size, font weight, font color,...) after doing mail merge</title>
      <dc:creator>Oliver</dc:creator>
      <pubDate>Thu, 11 Apr 2019 04:06:42 +0000</pubDate>
      <link>https://dev.to/gialoui/style-not-remain-including-font-size-font-weight-font-color-after-doing-mail-merge-47mo</link>
      <guid>https://dev.to/gialoui/style-not-remain-including-font-size-font-weight-font-color-after-doing-mail-merge-47mo</guid>
      <description>&lt;p&gt;I’m working with the Aspose and facing these problems:&lt;/p&gt;

&lt;p&gt;Style applied on the merge fields all lost after merging:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_sMSvkLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r9t4grkk2mbq5la9ijr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sMSvkLC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r9t4grkk2mbq5la9ijr1.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, i tried with another approach by removing the MERGEFIELD keyword inside field code, the applied style retained properly but not so really. Merge fields that had been removed these keywords piled up on top of the document (Please ignore the copyright warning):&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6OL6A8pm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/33i9tjy8op7dljyjua5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6OL6A8pm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/33i9tjy8op7dljyjua5j.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my code to execute the mail merge process:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void generateMailMergePdfFromJson(Document template, String json, String outputFilePath) throws ParserConfigurationException, SAXException, IOException, Exception {
    //Remove merge field with empty value and if the row are empty=&amp;gt; remove paragraph
    template.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS
            | MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS
            | MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS
            | MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);

    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonNode = objectMapper.readTree(json);

    ArrayNode arrayNode = objectMapper.createArrayNode();
    arrayNode.add(jsonNode);

    JsonNode rootNode = objectMapper.createObjectNode();

    ((ObjectNode) rootNode).set(Dictionary.ROOT_TAG_NAME, arrayNode);

    //To call custom merge data with html code
    template.getMailMerge().setFieldMergingCallback(new HandleMergeFieldInsertHtml());

    // Add main merge field based of main root tag name
    template.accept(new TableTagHandler(Dictionary.ROOT_TAG_NAME));
    // Merge fields
    template.getMailMerge().executeWithRegions(new JsonMailMergeDataSet(new JsonDocument(rootNode, Dictionary.ROOT_TAG_NAME)));

    template.save(outputFilePath, SaveFormat.PDF);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Anyone who has been working with Aspose, please give me an advice on this one.&lt;/p&gt;

</description>
      <category>aspose</category>
      <category>java</category>
      <category>word</category>
      <category>template</category>
    </item>
  </channel>
</rss>
