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

File corruption likely due to duplicate image IDs in document #190

Closed
KAVA-Leigh opened this issue Feb 15, 2021 · 7 comments
Closed

File corruption likely due to duplicate image IDs in document #190

KAVA-Leigh opened this issue Feb 15, 2021 · 7 comments
Labels

Comments

@KAVA-Leigh
Copy link

Hi guys,

First of all, I don't think this is actually any issue with the package at all, but have a strange scenario..
We have 2 separate document templates, both of them should be pulling in the same set of images (using IMAGE tag)-
but in 1 document, the file is perfect, the other always shows the error in Word that the document is corrupted. After letting Word recover it, the document all looks perfect.

So, there seems to be something else in the template that is causing an issue, but, only when the images are inserted (no matter where the image is inserted within the template & no matter what URL is provided). Both documents use the same set of URL's, the same image dimensions & the same additionalJSContext function called - so I know it works & has worked for many other templates.

Being that it is hard to even reproduce the issue (unfortunately I can't share the template with you in entirety, as it belongs to our customer), I am really just wondering if there are any methods you may know that can help locate the source of the corruption in the document?

Word just magically resolves the issue, but without indication of what it did to fix it & looking at the XML hasn't helped, as I don't really know what I am looking for.

I tried a Microsoft SDK that was suggested online, but I have little/no idea when it comes to .net & I couldn't get it to read the file (probably because I am on Mac), plus I am not really sure if it would have provided the answer for this issue.

Happy for you to just close this off, if there is nothing that comes to mind.
Thanks :)

@jjhbw
Copy link
Collaborator

jjhbw commented Feb 15, 2021

Hmmm this issue comes to mind #144 .

Also, have you tried saving the offending template again in the newest version of Word? Maybe edit it a bit to ensure Word actually parses and serialises it again. That way it may clean up some of the offending xml. Just a shot in the dark.

@KAVA-Leigh
Copy link
Author

Hi Jurriaan,

Thanks so much for getting back to me.

I had looked at several issues to see if there was something similar & missed the one you referenced.

The ID seems to be a really good potential for the issue, so I will give that a try.

I am using the latest Word version, but will see how the image ID fix goes (ensuring unique) - I have a feeling that may be it..

@KAVA-Leigh
Copy link
Author

Hi Jurriaan,

I gave this a try & haven't had any success yet, but I am convinced that the ID's mentioned in #144 is the issue.
When docx-templates inserts the images, it appears to start at id 1 - which in my case, was already used in the template (document.xml file). re-numbering the ID's in the template didn't work for me (ensuring that no ID below 10 was used)- it actually resulted in further corruption. Could be to do with <pic:cNvPr> elements that share ID's with <wp:docPr> elements perhaps, not sure - maybe they also need their ID's changed.

If I allow Word to recover a document, it changes the ID's of the images inserted - so I would imagine it does this for a reason & hence why I think the ID's are the issue.

I will revert if I manage to figure this out at some point anyway, appreciate the suggestions.

Thanks, Leigh.

@jjhbw
Copy link
Collaborator

jjhbw commented Feb 16, 2021

@KAVA-Leigh that sounds interesting and something we can improve docx-templates with. Having pre-existing images in the template seems like a common enough use case. Let me know if you find anything else!

@valstu
Copy link

valstu commented Jun 3, 2021

@KAVA-Leigh did you find any solutions for this? I have exactly the same issue now with existing images on the template.

@jjhbw jjhbw reopened this Jun 3, 2021
@jjhbw
Copy link
Collaborator

jjhbw commented Jun 3, 2021

@valstu can you post a small template + a code snippet for reproduction?

I reopened this issue because I intend to tackle it along with #144, and want to ensure my fix solves both problems.

@jjhbw jjhbw added the bug label Jun 3, 2021
@jjhbw jjhbw changed the title File Corruption Debugging File corruption likely due to duplicate image IDs in document Jun 3, 2021
jjhbw added a commit that referenced this issue Jun 3, 2021
…se in the template before rendering to ensure that image IDs are globally unique.
@jjhbw
Copy link
Collaborator

jjhbw commented Jun 3, 2021

Should be fixed in v4.6.2. Will be published to NPM shortly.

@jjhbw jjhbw closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants