合并邮件后样式不剩余(包括字体大小,字体粗细,字体颜色等)

时间:2019-04-11 03:31:02

标签: java styles aspose aspose.words aspose.pdf

我正在使用Aspose并面临以下问题:

应用于合并字段的样式在合并后全部丢失: example

然后,我尝试了另一种方法,方法是删除域代码中的MERGEFIELD关键字,所应用的样式正确保留,但并非如此。合并已删除的字段,这些关键字堆积在文档顶部(请忽略版权警告): example

(我没有完全的权限在此处嵌入图片,因此请通过我在这篇文章中附加的链接进行访问)

这是我执行邮件合并过程的代码:

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=> 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);
}

任何与Aspose合作的人,请给我一个建议。

0 个答案:

没有答案