我正在插入图像,这是我的代码:
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)
{
if (this.mBuilder == null)
this.mBuilder = new DocumentBuilder(e.Document);
string filename = GetFilePath();
if (!File.Exists(filename))
{
//todo insert text "<Image not found>" instead image
this.mBuilder.MoveToField(e.Field, false);
this.mBuilder.Write("<Image not found>");
e.ImageFileName = string.Empty;
return;
}
e.ImageFileName = filename;
}
如果图像不存在,我想插入文本"<Image not found>"
。但是这段代码会引发错误Cannot load image from field '...'. The field contains data in unsupported format. Could not find file
。
我应该插入什么来修复我的错误?
答案 0 :(得分:0)
这解决了我的问题。我只需要将字段删除到我的if
语句中即可:
this.mBuilder.MoveToField(e.Field, false);
this.mBuilder.Write("<Image not found>");
e.Field.Remove();
return;