I have a Base64 encoded image that looks like the following:
我有一个Base64编码的图像,如下所示:
var base64SignatureImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOgAAACJCAMAAAAR34S1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAA8PDx8fHy8vLz8/P09PT19fX29vb39/f4+Pj5+fn6+vr7+/v8/Pz9/f3+/v7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK/M6GAAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjb8jGPfAAALWklEQVR4Xu2da6Ojqg6GQVFREdb//7PdCSAXwUsLtp211/thH6fTaX0ghCTEHvL4n+gP9LfpD/S36Q/0t+kP9LfpDzSvhXcNQVHGF/vav6FnQFWPkJRpUUKYsH/xL+g6qGBAOUzK/vEhx4b09vof0FVQxSlpPaXRRP8d0ougM2La60BLM9irezWVL5JLoKoDo7XXsRb6DpfUk8Zeva4roEtL6Gyvtxo7e3GjJnAOxVN6AXShhG0Wp5cg0l7dJ0rGoXiJnIMC54HLEeVjfaYJlo1s7R9e1imoojvL02ig9uI+tRTsqXiRnoIyMtqrrJrbNxipB5qVOr0zUE6YvcqK379EzVfw0hVyAqoo2s2uFsrt1X1q9fK8G3Qke/sKaqb3by7KLB2eCVee0gloc2S4I2mPpruOJrM4eKnpHIPOBxMqWtLdz/nojL/lR5Z1Rcegw94KVTNEhaXWdEnUbG43r1GWXYNqBErC7w+JQGtAcjMoyayMpYOcm3Rvqi9wYmxquBk0CRYUFhna4W1lFGa94X60fVEnoKUuoFirTd0cAr4hHjiWsEMtbwZlny6VjNYXjcU3cgz6htzkWL0BVeWmdQy6fGqRKjFzrouqLdZWm8NU8ZKOQR9NebHmWcmZAx9lHDSYKjLuZ33hkJ+AYnb/Rqm5B6hmGG0wMtqv74G0MBA7AX00x3l3VWFYCZTB1HXEbNgNLNG5KYoZzkCXlrTviQ4gSSBNH8PYl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LB0VNCHxNL9o12N6x4rMWGpIw/aPeF1tcLdzoEO63k4FtwN8vMP94PD1qMhaXrq8ao8aHgSeUVRqdOkiYo3a/qAma29yRcecBj0Z4tsjvKiPKgLcq4p9rMLaTkfqGtvAE43DC90B8E/H3h/8CDy8/Kg5oHUq4JkKno3xqp+J4AdxO8Kr7RB4bFcV8sPaQWgzzQhQ7IRj4oSwvPEJ1zf8QMcAegTTcgQZx95CRYVn78PFPbwa9Zy4iX62Ffe0pf0tEJQALg0p9Pxnt9vRqFWbFOmCBRJz2Po4dgbjtvZ/kZQtN6Tvtxlc8S81fqQlZOsFtwUaQP6UOzwAEHxnQLcqiUJTkWlPKtQW1DY9iCt2CmPyqlpjvtYVZtgjU/FIbcpBdUPLBCsA2wkWPocw1ZdaqebJzw+pQwoWhsmWGyYhDu2GyEgOz/lzcXLlUohpcqCwqyOuv1qFWXDlebfJZO8m67bz2sHFCTHHmHbnk+nM2mkcint8B2+6AD0eQ25ycv9gtcnVBE0+xtOMvfiJ1QPVKUd76DxS5ZoRdBNX5DVm35m7lzVQHMeFy23Ulm2WNVA22xt7eNPwzvVAp3ymfj3/BRkJdCd3w/AZtQvUSVQni+s3dNX9pLqgO5MqD+b+bzqgO5MaNh59WnVAc1P6M7zr59RFdAp3xVgf+jkO1QFNP9zj7LCj8XWUw1QselfsOq/Z28B1QANWgMDLZlWsg+qBqjr+IuU9nB+VBVAtw/7Gc3f5HJBFUBdO2Ao5Vr9vkQVQLM+15xZf5HKQbMn5WFX/3eoHDT3+MD11t+3qRw0asW0ck8Gfo9uAR2+zOOi7gCd4+fXvkM3gC5nz0J9ROWg24dwl2/bQY3KQfXDjF5LzXaviioHfQRPruL8njdvfkQVQLmfUsmuNG9+RBVAH61tT1Kclv0a452qASobMggxdfst1V+gGqDYykLIl///i1UB/Rf0B/rb9Af62/QH+rv0ePwHhuJkw/TfPG4AAAAASUVORK5CYII=";
Using the Word Automation API, how can I insert this as a picture in a Word document in memory?
使用Word Automation API,如何将它作为图片插入到Word文档的内存中?
Preferably without use of system clipboard, or inserting from file.
最好不使用系统剪贴板,或从文件中插入。
1 个解决方案
#1
2
The only possibility to insert a graphic from base64 is to use Word Open XML.
从base64插入图形的唯一可能是使用Word Open XML。
In order to do this via the APIs you need to generate valid Word Open XML in the OPC flat-file format. This can be inserted into the document open in the Word application using the Range.InsertXML method.
为了通过api实现这一点,您需要在OPC平面文件格式中生成有效的Word Open XML。这可以在使用范围的Word应用程序中插入到文档中。InsertXML方法。
The easiest way to determine what the valid Word Open XML is, is to write it out to a string using the Range.WordOpenXML property. For example, insert the image as an InlineShape then Document.InlineShapes[index].Range.WordOpenXML;
确定有效单词Open XML的最简单方法是将其写入到使用范围的字符串中。WordOpenXML财产。例如,将图像作为InlineShape插入Document.InlineShapes[index].Range.WordOpenXML;
Or, using the the Immediate Window in the VBA editor and writing it to the current Selection in the document:
或者,使用VBA编辑器中的即时窗口,将其写入文档中的当前选择:
Selection.Text = ActiveDocument.InlineShapes(1).Range.WordOpenXML
then press Enter.
然后按回车键。
You should see the image as base64 in the XML.
在XML中,应该将图像看作base64。
This generates the full, complete Word Open XML and you can use it "as is", substituting the base64 (and possibly adjusting size properties). But you don't need all of that for InsertXML. If you'd like to trim it down, or understand more about what's going on, this article explains what the minimum requirements are and provides more background information:
这将生成完整的、完整的Word Open XML,您可以使用它“as is”,替换base64(并可能调整大小属性)。但对于InsertXML不需要所有这些。如果你想精简它,或了解更多的情况,这篇文章解释了最低要求是什么,并提供更多的背景信息:
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx
#1
2
The only possibility to insert a graphic from base64 is to use Word Open XML.
从base64插入图形的唯一可能是使用Word Open XML。
In order to do this via the APIs you need to generate valid Word Open XML in the OPC flat-file format. This can be inserted into the document open in the Word application using the Range.InsertXML method.
为了通过api实现这一点,您需要在OPC平面文件格式中生成有效的Word Open XML。这可以在使用范围的Word应用程序中插入到文档中。InsertXML方法。
The easiest way to determine what the valid Word Open XML is, is to write it out to a string using the Range.WordOpenXML property. For example, insert the image as an InlineShape then Document.InlineShapes[index].Range.WordOpenXML;
确定有效单词Open XML的最简单方法是将其写入到使用范围的字符串中。WordOpenXML财产。例如,将图像作为InlineShape插入Document.InlineShapes[index].Range.WordOpenXML;
Or, using the the Immediate Window in the VBA editor and writing it to the current Selection in the document:
或者,使用VBA编辑器中的即时窗口,将其写入文档中的当前选择:
Selection.Text = ActiveDocument.InlineShapes(1).Range.WordOpenXML
then press Enter.
然后按回车键。
You should see the image as base64 in the XML.
在XML中,应该将图像看作base64。
This generates the full, complete Word Open XML and you can use it "as is", substituting the base64 (and possibly adjusting size properties). But you don't need all of that for InsertXML. If you'd like to trim it down, or understand more about what's going on, this article explains what the minimum requirements are and provides more background information:
这将生成完整的、完整的Word Open XML,您可以使用它“as is”,替换base64(并可能调整大小属性)。但对于InsertXML不需要所有这些。如果你想精简它,或了解更多的情况,这篇文章解释了最低要求是什么,并提供更多的背景信息:
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx
https://msdn.microsoft.com/en-us/library/office/dn423225.aspx