使用复选框将Word Doc设置为PDF无效

时间:2018-07-26 18:31:02

标签: java aspose aspose.words aspose.pdf

嗨,我正在尝试使用docx模板中的邮件合并字段将docx转换为pdf。 这就是我的简单模板的样子

 <<isMemberOfGroup>> MEMBER OF GROUP

isMemberOfGroup是一个布尔字段。我期望它显示一个标有X的复选框(如果为true,否则留空)。

这是使用aspose.words库(版本17.6)的代码

 final int option = template.getMailMerge().getCleanupOptions() | MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS;
  template.getMailMerge().setCleanupOptions(option);
  template.getMailMerge().setFieldMergingCallback(new HandleMergeField());
  template.getMailMerge()
          .execute(valueMap.keySet().toArray(new String[0]),
                   valueMap.values().toArray(new Object[0]));
  final ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
  template.save(pdfStream, SaveFormat.PDF);
  return pdfStream.toByteArray();

这是合并字段处理程序的代码

 public class HandleMergeField implements IFieldMergingCallback {

private DocumentBuilder mBuilder;
/**
 * This handler is called for every mail merge field found in the document,
 * for every record found in the data source.
 */
@Override
public void fieldMerging(FieldMergingArgs e) throws Exception {
    if (mBuilder == null) {
        mBuilder = new DocumentBuilder(e.getDocument());
    }

    // We decided that we want all boolean values to be output as check box form fields.
    if (e.getFieldValue() instanceof Boolean) {
        // Move the "cursor" to the current merge field.
        mBuilder.moveToMergeField(e.getFieldName());

        // It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
        String checkBoxName = java.text.MessageFormat.format("{0}{1}", e.getFieldName(), e.getRecordIndex());

        // Insert a check box.
        mBuilder.insertCheckBox(checkBoxName, (Boolean) e.getFieldValue(), 0);

        // Nothing else to do for this field.
        return;
    }
}

@Override
public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception {
    // Do nothing.
}

}

我面临的问题是,pdf没有显示实际的复选框。而是显示

 success(true) MEMBER OF GROUP 

我希望看到一个标记的复选框,而不是成功(true)。
我想念什么吗?提前致谢。

0 个答案:

没有答案