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

Multiple redundant copies of the image are inserted in the resulting docx file #218

Closed
DidiF45 opened this issue Jul 5, 2021 · 4 comments

Comments

@DidiF45
Copy link

DidiF45 commented Jul 5, 2021

First of all thank you so much for this library. It is so powerful !!!
I encountered a problem after upgrading the version of docx-template.
I was using the version 2.7.2 with images in the docx template and the generated docx file has a correct size (6137 Ko).
After upgrading to the lastest version 4.6.4, for the same docx template I get a docx file of 84 109 Ko (13 times bigger !)
So I had a look at the xml content of the file and saw that in the new version, the file contains for example 14 times the same image (see capture1.png)
In version 2.7.2 the same image appears only once (see capture2.png).
Why are the images repeated several times in the xml content ?
Capture1
Capture2

Thank you for your help !

@jjhbw
Copy link
Collaborator

jjhbw commented Jul 6, 2021

Thanks for reporting. That sure is strange. A few checks just to be sure: you are using exactly the same template and createReport invocation? Did you use the IMAGE command for both templates, or did you use the older deprecated replaceImages API?

@DidiF45
Copy link
Author

DidiF45 commented Jul 6, 2021

Thanks for reporting. That sure is strange. A few checks just to be sure: you are using exactly the same template and createReport invocation? Did you use the IMAGE command for both templates, or did you use the older deprecated replaceImages API?

Thank you for your reply.
Yes I'm using the same template and the createReport invocations are as follows :
In 2.7.2

var createReport = require('docx-templates');
createReport({
                template: filepath,
                data: body,
                noSandbox: true,
                output: filepath,
                literalXmlDelimiter: '||',
                processLineBreaks: true
}).then(function(report) { ... });

In 4.6.4

var createReport = require('docx-templates').createReport;
createReport({
                template: fs.readFileSync(filepath),
                data: body,
                noSandbox: true,
                literalXmlDelimiter: '||',
                processLineBreaks: true
}).then(function(report) {
 fs.writeFileSync(filepath , report);
 ... });

I'm using IMAGE command.

@jjhbw jjhbw changed the title The same image is added up 13 times in all media components making the docx file bigger When inserting identical images in different IMAGE commands, multiple redundant copies of the image are inserted in the resulting docx file, leading to bloat. Jul 7, 2021
@jjhbw jjhbw changed the title When inserting identical images in different IMAGE commands, multiple redundant copies of the image are inserted in the resulting docx file, leading to bloat. Multiple redundant copies of the image are inserted in the resulting docx file Jul 10, 2021
jjhbw added a commit that referenced this issue Jul 10, 2021
jjhbw added a commit that referenced this issue Jul 10, 2021
… when IMAGE is used in doc header, the PNG file is added twice to word/media/.
jjhbw added a commit that referenced this issue Jul 10, 2021
jjhbw added a commit that referenced this issue Jul 10, 2021
… when IMAGE is used in doc header, the PNG file is added twice to word/media/.
@jjhbw
Copy link
Collaborator

jjhbw commented Jul 11, 2021

Fixed in master by 636db40. This problem was caused by my naive fix for #217 (5f2da67).

@jjhbw jjhbw closed this as completed Jul 11, 2021
@jjhbw
Copy link
Collaborator

jjhbw commented Jul 12, 2021

Fix released in v4.7.0. Should be on NPM shortly.

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