Free Support Forum - aspose.com

MergeImageFieldEvent using Memorystream.Write

Below you will see the code that I am trying to use that basically appends two images into one using the memorystream.write method.

If I debug and watch the length of the memory stream before assigning to e.imagestream, everything looks fine. The problem comes in where after the merge, only the last image shows. It appears to be the last image written to the memory stream.

So, I'm basically stuck. Am I completely going about this the wrong way?

Thanks,

wowaddict

private void HandleMergeSignature(object sender, Aspose.Words.Reporting.MergeImageFieldEventArgs e)

{

MemoryStream memorybits = new MemoryStream();

foreach (ImageEntity peiie in myImages)

{

byte[] bits = (byte[])(peiie.ExamImageBinary);

memorybits.Write(bits, 0, bits.Length);

}

memorybits.Seek(0, SeekOrigin.Begin);

e.ImageStream = memorybits; //length is correct but only 1 image displays (last written to memorystream)

}

Hi

Thanks for your inquiry. You can’t insert several images into one merge field. I think that you can try using DocumentBuilder to achieve what you want. See the following code for example.

private void HandleMergeSignature(object sender, Aspose.Words.Reporting.MergeImageFieldEventArgs e)

{

//Create document builder

DocumentBuilder builder = new DocumentBuilder(e.Document);

//Move to mergefield

builder.MoveToMergeField(e.FieldName);

foreach (ImageEntity peiie in myImages)

{

//Insert Images

byte[] bits = (byte[])(peiie.ExamImageBinary);

builder.InsertImage(bits);

}

}

I hope this could help you.

Best regards.

Excellent, that works and is what I needed.

Thanks.