Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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>
Posted
Updated 24-Sep-17 23:12pm
v2

1 solution

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)
 
Share this answer
 
Comments
Member 13340867 25-Sep-17 6:09am    
Thanks sandeep,its not working
Member 13789698 6-Dec-18 3:05am    
How to use above code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900