[英]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".我正在尝试在从 angular 生成的 Word 文档中显示图像,其中包含 docx npm package,但我得到一个带有红色 X 的空图像和文本“无法显示”。
I know docx supports jpeg, jpg, bmp, gif and png, and I have tried with png.我知道 docx 支持 jpeg、jpg、bmp、gif 和 png,并且我尝试过使用 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.您必须在 base64 中转换图片。 Found the answer finally.
终于找到了答案。 Thank you!
谢谢!
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)], });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.