Hi,
Thank you for the quick response.
I will try to explain our issue a little more detailed.
The string inside the <Picture>
element is a byte string, and is handled as follows:
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
{
if (!string.IsNullOrEmpty(args.FieldValue.ToString()))
{
byte[] l_bytes;
try
{
l_bytes = Convert.FromBase64String(args.FieldValue.ToString());
}
catch (Exception l_e)
{
l_e.Data.Add("FielName", args.FieldName);
throw;
}
var l_builder = new DocumentBuilder(args.Document);
InsertImage(args.FieldName, l_bytes, l_builder);
}
}
And the byte array is handled in InsertImage:
// Create stream with image
using (Stream l_stream = new MemoryStream(l_bytes))
{
var l_image = Image.FromStream(l_stream);
// Calculate height or width to keep aspect ratio when resizing image
CalculateSizeWithRatio(l_image, l_width, l_height, out l_width, out l_height);
}
This is working properly, and is not the problem.
We experience the problem when some of our xml elements does not contain data.
This XML does work:
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Group1>
<Tables>
<Table>
<Picture>iVBORw0KGgoAAAANSUhEUgAAABYAAAAZCAIAAAC6gEm5AAAAK3RFWHRDcmVhdGlvbiBUaW1lAG1hIDI0IG9rdCAyMDExIDE5OjAyOjMxICswMTAwhqSkGgAAAAd0SU1FB9sKGBEDD81GpogAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAEZ0FNQQAAsY8L/GEFAAAAH0lEQVR42mM8fus9A2WAcdSIUSNGjRg1YtSIUSMoAADauUAqsktYDQAAAABJRU5ErkJggg==</Picture>
</Table>
</Tables>
</Group1>
<Group2>
<Tables>
<Table>
<Picture>iVBORw0KGgoAAAANSUhEUgAAABYAAAAZCAIAAAC6gEm5AAAAK3RFWHRDcmVhdGlvbiBUaW1lAG1hIDI0IG9rdCAyMDExIDE5OjAyOjMxICswMTAwhqSkGgAAAAd0SU1FB9sKGBEDD81GpogAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAEZ0FNQQAAsY8L/GEFAAAAH0lEQVR42mM8fus9A2WAcdSIUSNGjRg1YtSIUSMoAADauUAqsktYDQAAAABJRU5ErkJggg==</Picture>
</Table>
</Tables>
</Group2>
</Report>
This does not work:
<?xml version="1.0" encoding="utf-8"?><Report xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Group2>
<Tables>
<Table>
<Picture>iVBORw0KGgoAAAANSUhEUgAAABYAAAAZCAIAAAC6gEm5AAAAK3RFWHRDcmVhdGlvbiBUaW1lAG1hIDI0IG9rdCAyMDExIDE5OjAyOjMxICswMTAwhqSkGgAAAAd0SU1FB9sKGBEDD81GpogAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAEZ0FNQQAAsY8L/GEFAAAAH0lEQVR42mM8fus9A2WAcdSIUSNGjRg1YtSIUSMoAADauUAqsktYDQAAAABJRU5ErkJggg==</Picture>
</Table>
</Tables>
</Group2>
</Report>
This may look like a bug in ExecuteWithRegions, as it does not handle the image insert when the same element name (“Picture”) is used both in “Group1” and “Group2” in the template, and one is missing the image data.