How to add images to a Word document from angular using docx?

I am trying to display an image in a Word document generated from angular with the docx npm package, but i get an empty image with a red X and a text “The picture can’t be displayed”.

I know docx supports jpeg, jpg, bmp, gif and png, and I have tried with png. Also I tried to convert to a byte array, but I’m still getting the same result.

Any help on this would be great, thanks!

const image = Media.addImage(document, "data:./assets/images/team/add.png;base64,", 400, 400);

document.addSection({
        children: [new Paragraph(image)],
    });

You have to transform the picture in base64. Found the answer finally. Thank you!

109 thoughts on “How to add images to a Word document from angular using docx?”

  1. Its like you read my mind! You seem to know so much about this,
    like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a little bit,
    but instead of that, this is wonderful blog.
    A fantastic read. I’ll certainly be back. http://droga5.net/

    Reply
  2. Unquestionably believe that which you stated.

    Your favorite reason seemed to be on the internet the simplest thing to be aware of.
    I say to you, I definitely get irked while people think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without having
    side-effects , people can take a signal. Will likely be back to get
    more. Thanks http://antiibioticsland.com/Stromectol.htm

    Reply