如何将base64 imgae as HTML转换为win文件中的word文档 [英] How to convert base64 imgae as HTML to word document in win forms
问题描述
我需要将html转换为word,所有文本都显示正确,但图片不会在word文档中呈现。
我尝试过:
例如:
< html>
< body>
< div>
< p>取自wikpedia< / p>
< ; img src =data:image / png; base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4 // 8 / w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg ==alt =红点/>
< / div>
< / body>
< / html>
I need to convert html to word,all text display proper but image not render inside word document.
What I have tried:
For example :
<html>
<body>
<div>
<p>Taken from wikpedia</p>
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
</div>
</body>
</html>
推荐答案
you can try to use "insertInlinePictureFromBase64".
Example:
var img = '' //a base64 encoded string
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy object for the document body.
var body = context.document.body;
// Queue a command to insert the image.
body.insertInlinePictureFromBase64(img, 'End');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
app.showNotification('Image inserted successfully.');
});
})
.catch(function (error) {
app.showNotification("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
app.showNotification("Debug info: " + JSON.stringify(error.debugInfo));
}
});
Reference:
Inserting a base64 encoded image into a Word 2016 document
Other references:
InlinePicture object (JavaScript API for Word)
Body object (JavaScript API for Word)
这篇关于如何将base64 imgae as HTML转换为win文件中的word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!