«Image:mPhoto»
While trying to insert a image i get the image merge field as well. Can any one tell me why does Image:mPhoto appear? It should be replaces by the image right?
I am using the following code.
CPRiskCADataSource CADataSource = new CPRiskCADataSource(CAList);
doc.getMailMerge().setFieldMergingCallback(new HandleMergeImageFieldFromBlob());
doc.getMailMerge().executeWithRegions(CADataSource);
private class HandleMergeImageFieldFromBlob implements IFieldMergingCallback
{
public void fieldMerging(FieldMergingArgs args) throws Exception
{
// Do nothing.
}
public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception
{
// The field value is a byte array, just cast it and create a stream on it.
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) e.getFieldValue());
// Now the mail merge engine will retrieve the image from the stream.
e.setImageStream(imageStream);
}
}
public class CPRiskCADataSource implements IMailMergeDataSource {
private RiskCAList mRiskCAList;
private int mRecordIndex;
public CPRiskCADataSource(RiskCAList analysisList) {
mRiskCAList = analysisList;
// When the data source is initialized, it must be positioned before the first record.
mRecordIndex = -1;
}
///
/// The name of the data source. Used by Aspose.Words only when executing mail merge with repeatable regions.
///
public String getTableName() {
return "riskCA";
}
///
/// Aspose.Words call this to get a value for every data field.
///
public boolean getValue(String fieldName, Object[] fieldValue) {
if ("fileName".equals(fieldName)) {
fieldValue[0] = mRiskCAList.get(mRecordIndex).getFileName();
return true;
} else if ("mPhoto".equals(fieldName)) {
fieldValue[0] = mRiskCAList.get(mRecordIndex).getAttach();
return true;
} else {
// A field with this name was not found,
// return false to the Aspose.Words mail merge engine.
fieldValue[0] = null;
return false;
}
}
///
/// A standard implementation for moving to a next record in a collection.
///
public boolean moveNext()
{
if (isEof())
return false;
mRecordIndex++;
return (!isEof());
}
private boolean isEof()
{
return (mRecordIndex>= mRiskCAList.size());
}
@Override
public IMailMergeDataSource getChildDataSource(String arg0)
throws Exception
{
// TODO Auto-generated method stub
return null;
}
}