Yes this is still occurring, on DataRow as well.
public static byte[] getFileBytes(File file) throws Exception {
int fileLength = (int) file.length();
byte[] fileBytes = new byte[fileLength];
FileInputStream fis = new FileInputStream(file);
fis.read(fileBytes, 0, fileLength);
fis.close();
return fileBytes;
}
// From here down is sample code.
// Open the template document.
Document doc = new Document("./template.docx");
// Get the MailMerge object for the doc and set some options for cleanup & formatting.
MailMerge mm = doc.getMailMerge();
mm.setCleanupOptions(
MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS |
MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS |
// Note: Comment out to see fields that are not updated in output doc.
MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS |
MailMergeCleanupOptions.REMOVE_STATIC_FIELDS
//MailMergeCleanupOptions.REMOVE_EMPTY_TABLE_ROWS
);
// Trim whitespace from merge inputs.
mm.setTrimWhitespaces(true);
// Allows using 'Mustache' syntax for mail merge template.
mm.setUseNonMergeFields(true);
DataTable dataTable = new DataTable();
DataRow dataRow = dataTable.newRow();
dataRow.getColumn().add("DocumentImage");
dataTable.getRows().add(dataRow);
dataRow.set("DocumentImage", getFileBytes(new File("./myImage.png")));
// Does not work
mm.execute(globalDataRow);
// Works.
//mm.execute(new String[]{ "DocumentImage" }, new Object[]{ getFileBytes(new File("./myImage.png") }));
doc.save("./output.pdf");
document should contain {{ Image:DocumentImage }}
Any chance of having the library updated to allow for images in DataRows/DataSet/DataTable and executeWithRegions?
Expectation: Image is merged into the document.