7

I have uncompressed a docx file (say file.docx) using 7zip to file/. (or alternatively, changed extension to .zip then extracted it)

I modified some images inside file\word\media\ and now i want to recompile/rebundle/repackage the folder into a docx file. I am using MS Office 2007.

How can i do that?

  • I tried zipping it back, then changing extension to docx, didn't work - msword showed corrupted file error, tried restoring/fixing it, failed, then exited with error.

As for the XY problem; i am trying to edit all the selected images in the docx via some manipulation (like magick and thereafter in gimp)

This question is similar in spirit to:

0

3 Answers 3

12

To correctly re-zip an unzipped .docx file, be sure to follow the following rules :

  • Replace the files in their original folder
  • Zip the contents of the folder and avoid the common error of zipping up the folder
  • Use Zip (DEFLATE64) compression.
3
  • 1
    I suspect you mean DEFLATE64 instead of Base 64?
    – Blackhawk
    May 15, 2023 at 14:58
  • 1
    @Blackhawk: Yes, this is indeed the precise name.
    – harrymc
    May 15, 2023 at 17:27
  • Ah yes, the CONTENTS! Thank you.
    – Moss
    Jun 6, 2023 at 4:35
2

I would clone the backup copy (you did make a backup, right?) and replace the files you modified directly in the DOCX "archive" instead of trying to fiddle with the extracted contents.

If you renamed your DOCX file as a ZIP, Windows Explorer can open it like a folder and you can do a limited level of editing directly with the archive.

1
  • Yes, this works best
    – jbs
    Apr 26 at 15:50
2

From: https://deparkes.co.uk/2016/12/23/how-word-files-store-images/

You may also need to update various XML files in the 'ZIP'. Excerpts from the page referred to:

"The docx xml stores properties about the images.

Within the ‘word’ folder in the unzipped docx document you’ll find document.xml which contains the structure of the document. Open this file up and you’ll see a series of ‘p’ – paragraph – elements which make up your document."

enter image description here

In this there are three p elements – one for each line of text and one for the image. In this case the image is the second of the paragraphs. We can explore the branches of this tree until we find “r:id” under “v:imagedata”.

enter image description here

Possibly the hex values are checksums? And if your modifications change for example dimensions and checksums, this may be what's causing the issues when opening the recompressed DOCX files.

I'll also include the URL to the video the page refers to: https://youtu.be/p9MqsEIHFXE

2
  • no, there is no problem with checksums, as i changed the images and it worked well (at least with MSO-W-2007). but thanks for digging deep 😃 May 27, 2023 at 4:56
  • @user8395964, feel free to upvote when it turns out to be step towards solution. and also mentioned dimensions. basically, the answer is just a means to dig deeper and determine what it is that upsets Word about your modified files. May 27, 2023 at 10:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .