// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java //Load a document from a BLOB database field private class InsertDocumentAtMailMergeBlobHandler implements IFieldMergingCallback { /** * This handler makes special processing for the "Document_1" field. The * field value contains the path to load the document. We load the * document and insert it into the current merge field. */ public void fieldMerging(FieldMergingArgs e) throws Exception { if ("Document_1".equals(e.getDocumentFieldName())) { // Use document builder to navigate to the merge field with the specified name. DocumentBuilder builder = new DocumentBuilder(e.getDocument()); builder.moveToMergeField(e.getDocumentFieldName()); // Load the document from the blob field. ByteArrayInputStream inStream = new ByteArrayInputStream((byte[]) e.getFieldValue()); Document subDoc = new Document(inStream); inStream.close(); // Insert the document. insertDocument(builder.getCurrentParagraph(), subDoc); // The paragraph that contained the merge field might be empty now and you probably want to delete it. if (!builder.getCurrentParagraph().hasChildNodes()) builder.getCurrentParagraph().remove(); // Indicate to the mail merge engine that we have inserted what we wanted. e.setText(null); } } public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception { // Do nothing. } }