39

I've had success unzipping and examining the interior of a .docx file, but I can't seem to get the re-zipping to work properly. I've tried no compression (command line: zip -0r ...), the archive utility, and a 7zip plugin but none of that works. All of the .docx files I create won't open in the original programs, even when I don't change a single file. Any tips?

Jeremy W
  • 3,629
  • 20
  • 35
acsmith
  • 493
  • 1
  • 4
  • 5

1 Answers1

51

It is important that the files that make up the docx are not within another folder, i.e. [Content_Types].xml must be in the root of the resulting zipped file. A similar question has been asked on StackOverflow.

When you open (or extract to the current directory) the zip file, you should have something similar to the following:

./docProps/
./word/
./_rels/
./customXml/
./[Content_Types].xml

If you have those files within another directory inside the zip or docx file, it won't work. Note that I don't get the customXml folder on an empty Word document, but the report I originally tested with did have it. You may have some more (or less) directories.

The command to rezip these, issued from the "current directory", is:

zip -r preso.pptx *
Bob
  • 60,938
  • 25
  • 191
  • 216
  • 2
    Thanks. I think the other key was to only edit things with the Terminal. Even after adding `-x .DS_Store`, it would still not work unless I didn't use the Finder to navigate, ever. So I just used textmate and all's well. – acsmith Apr 13 '12 at 04:41
  • 1
    I'm not sure, not having a Mac to test on, but a problem may be caused by Mac and its apps defaulting to the `CR` [newline marker](http://en.wikipedia.org/wiki/Newline) and Word expecting a `CR+LF`, even though [the XML specifications say](http://www.w3.org/TR/REC-xml/#sec-line-ends) to treat them all the same way. I can't say whether Word follows that specification properly or not. There could also be some unexpected encoding changes, or even a hidden file created, once again I can't say anything for sure. It seems you have found a workaround anyway. – Bob Apr 13 '12 at 04:48
  • 1
    Yeah, I think it was the Finder. I can even open the xml files in textmate or whatever, edit, save, and as long as I do all the zipping/viewing/unzipping in the terminal it's fine. Seems to work now -- the root file thing was the problem. Thanks. – acsmith Apr 20 '12 at 04:45