Docx: How to add an image from a buffer into a document?

Created on 5 Jul 2018  路  5Comments  路  Source: dolanmiu/docx

Hello,

I'm using [email protected].

The code below returns doc.createDrawing is not a function :

const doc = new docx.Document();
const paragraph = new docx.Paragraph('Some text.');
paragraph.addRun(new docx.TextRun('Some text run.'));
doc.addParagraph(paragraph);
const buff = fs.readFileSync('/tmp/w3c_home.png');
const image_data = doc.createImageData('Dummy dummy', buff);
doc.createDrawing(image_data);

What am I doing wrong?

feature request

Most helpful comment

Yes, I am in the process of remaking the API, i agree it is a bit convoluted

All 5 comments

Maybe related to #89

doc.Document.createDrawing(image) works perfectly, thanks a lot!

It's just a bit strange for the API to offer createImageData on the doc instance, while createDrawing must be accessed through a sub-object/property Document.

I leave it to you to close this ticket or not, depending on whether you consider that there is an API problem or not.

In any case: thank you again!

Yes, I am in the process of remaking the API, i agree it is a bit convoluted

Thanks a lot for your answer and your package!

Was this page helpful?
0 / 5 - 0 ratings