Alex Alexa
Alex Alexa

Reputation: 107

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!

Upvotes: 2

Views: 2469

Answers (1)

hung lee
hung lee

Reputation: 1

Try this one

const base64data = "ashvbly3458absfjbscldvsbvsVslfghdf...";//Base64 Image String
const imageb64 = Media.addImage(document, Uint8Array.from(atob(base64data), c => c.charCodeAt(0)), 80, 80);

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

Upvotes: -1

Related Questions