OpenOffice 3.2 Graphic File Link Hackage

OpenOffice normally stores graphic file links relative to the location of the ODT document file. It’s an option at Tools -> Options -> Load/Save -> General, where you check Save URLs relative to file system.

That generally works well, as long as you keep all the graphics either in the same directory or in a subdirectory, which is our general practice. Note that this doesn’t apply if you embed the image files into the document, which works fine for one-pagers and dies horribly for lengthy graphics-intense documents.

(Yes, I know OOo is not a page layout program. Sometimes other considerations get in the way. Work with me on this, OK?)

It’s easy to confuse the program: copy the ODT file somewhere else and, shazam, the links either break or get weird. In a recent case, the links somehow wound up holding the entire path from the root directory through /home, down through an NFS mount, and out to the actual file. Not only was it un-pretty, the links basically didn’t work from any other account on any other machine because you really can’t reach through another user’s account to your files.

This is tedious, at best, to fix up within OpenOffice, because you can’t do a find-and-replace on the file names.


In OOo, click through Tools -> Options -> Load/Save -> General. Uncheck the Size optimization for ODF format option to force the XML file to become human-readable. Otherwise, OO stores everything as one huge line. While you’re there, make sure Save URLs relative to file system is checked.

Save the file again to get readable XML.

Create /tmp/work, copy the ODT file therein, apply unzip to it. That extracts the contents, including the all-important  content.xml containing your document’s text & links.

Edit content.xml with the text editor (not a word processor like OOo!) of your choice. Bulk-change the garbage paths to something meaningful. For example, we had all the images in Tweaked, a subdirectory below the document directory, so the desired file links looked like ../Tweaked/image-file-name.jpg.

Save the file and stuff it back into the ODT file using zip -vi document.odt content.xml

That produced some odd error messages that didn’t seem to have any effect:

	zip warning: undefined bits used in flags = 0x0808: layout-cache
	zip warning: undefined bits used in flags = 0x0808: content.xml
	zip warning: undefined bits used in flags = 0x0808: styles.xml
	zip warning: undefined bits used in flags = 0x0808: Thumbnails/thumbnail.png
	zip warning: undefined bits used in flags = 0x0808: settings.xml
	zip warning: undefined bits used in flags = 0x0808: META-INF/manifest.xml
updating: content.xml
	zip warning: Local Entry CRC does not match CD: content.xml
	(in=54496) (out=7765) (deflated 86%)
total bytes=91294, compressed=17644 -> 81% savings

OOo stores the file timestamps within the ODT file in UTC, confusing the daylights out of zip, which assumes they’re in local time. Being at UTC-4 right now, I couldn’t simply freshen or update a recently created ODT file.

Copy the modified ODT file back where it came from, make sure the graphic files are where you promised they’d be, and open the document.

Everything should be just fine.

One thought on “OpenOffice 3.2 Graphic File Link Hackage

Comments are closed.