Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add an image from a buffer into a document? #91

Closed
madarche opened this issue Jul 5, 2018 · 5 comments
Closed

How to add an image from a buffer into a document? #91

madarche opened this issue Jul 5, 2018 · 5 comments

Comments

@madarche
Copy link

madarche commented Jul 5, 2018

Hello,

I'm using docx@3.6.0.

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?

@madarche
Copy link
Author

madarche commented Jul 5, 2018

Maybe related to #89

@dolanmiu
Copy link
Owner

dolanmiu commented Jul 5, 2018

Can you try this?

https://github.com/dolanmiu/docx/blob/feat/base64-image/demo/demo18.js

@madarche
Copy link
Author

madarche commented Jul 6, 2018

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!

@dolanmiu
Copy link
Owner

dolanmiu commented Jul 9, 2018

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

@madarche
Copy link
Author

madarche commented Jul 9, 2018

Thanks a lot for your answer and your package!

@madarche madarche closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants