Converting a <V:shape>/Embed to a w:drawing

被刻印的时光 ゝ 提交于 2019-12-02 04:48:05
Stuart.Sklinar

I found a quick/simple way to do this - and I should have worked it out earlier!

The Shape object has a ImageData object as a descendant, so I checked for that, and ran it through an extra method to get the ImagePart:

A.Blip pic = item.Descendants<A.Blip>().FirstOrDefault();

ImageData imageData = item.Descendants<ImageData>().FirstOrDefault();

if (pic == null && imageData == null) //pictures are processed differently - they're an absolute s**t storm to code...
{
  runToAmend.InsertAfterSelf(item.CloneNode(true));
}
else
{
  if(pic != null)
  {
    runToAmend.InsertAfterSelf(CreateImageFromBlip(source, item, footerHeaderPart,pic));
  }
  else if (imageData != null)
  {
    runToAmend.InsertAfterSelf(CreateImageFromShape(source, item, footerHeaderPart, imageData));
  }
}

Then created a new method - CreateImageFromShape(..) which then calls the original CreateImageRun.

private Run CreateImageFromShape(WordprocessingDocument sourceDoc, Run sourceRun, OpenXmlPart headerFooterPart, ImageData imageData)
{
  ImagePart p = sourceDoc.MainDocumentPart.GetPartById(imageData.RelationshipId) as ImagePart;

  return CreateImageRun(sourceDoc, sourceRun, headerFooterPart, p);
}

Job done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!