Editing OpenOffice.org documents from the commandline
Thursday, January 20th, 2011I’ve just put together a reasonably big document with a load of content copy/pasted from a web page (in this case, a firewall configuration GUI). Everything looked fine. Then I closed the VPN to the remote firewall … and all the icon images I’d pasted broke! When they were pasted in, by default only links to the graphics were added, instead of copies …
Luckily for me, I was using OpenOffice.org, a wordprocessor with a sensible internal file storage.
To fix my document all I needed to do was to unpack my .odt file into a temporary location, grab local copies of the icons (I populated ~/tmp/fwicons/ from a different firewall, as it happens) into the Pictures/ directory, change all the old image URLs into filenames (just by changing their prefix from http://something/... to Pictures/), and repack the changes into the original document.
OpenOffice.org detected my monkeying around internally, and insisted on running a quick “repair” over the file; when that was done I had all my lovely icons back again!
Here’s the complete command-line session …
jim@hex:~/ORIG$ mkdir ~/tmp/fixdoc jim@hex:~/ORIG$ cp Network\ Configuration\ 1.0.odt /home/jim/tmp/fixdoc/ jim@hex:~/ORIG$ cd /home/jim/tmp/fixdoc/ jim@hex:~/tmp/fixdoc$ ls -l total 80 -rw-r--r-- 1 jim jim 73421 2011-01-20 18:29 Network Configuration 1.0.odt jim@hex:~/tmp/fixdoc$ mkdir unpack jim@hex:~/tmp/fixdoc$ cd unpack jim@hex:~/tmp/fixdoc/unpack$ unzip ../Network\ Configuration\ 1.0.odt Archive: ../Network Configuration 1.0.odt extracting: mimetype extracting: Pictures/10000201000001ED000001882B8674A7.png inflating: content.xml inflating: layout-cache inflating: manifest.rdf inflating: styles.xml extracting: meta.xml inflating: Thumbnails/thumbnail.png inflating: Configurations2/accelerator/current.xml creating: Configurations2/progressbar/ creating: Configurations2/floater/ creating: Configurations2/popupmenu/ creating: Configurations2/menubar/ creating: Configurations2/toolbar/ creating: Configurations2/images/Bitmaps/ creating: Configurations2/statusbar/ inflating: settings.xml inflating: META-INF/manifest.xml jim@hex:~/tmp/fixdoc/unpack$ cp ~/tmp/fwicons/*gif Pictures jim@hex:~/tmp/fixdoc/unpack$ perl -pi -e 's|http://firewall/themes/pfsense_ng/images/icons/|Pictures/|g' content.xml jim@hex:~/tmp/fixdoc/unpack$ zip -r ../Network\ Configuration\ 1.0.odt Pictures/* adding: Pictures/icon_block_d.gif (deflated 15%) adding: Pictures/icon_block.gif (deflated 17%) adding: Pictures/icon_log_d.gif (deflated 28%) adding: Pictures/icon_log.gif (deflated 30%) adding: Pictures/icon_log_s.gif (deflated 29%) adding: Pictures/icon_pass_d.gif (deflated 7%) adding: Pictures/icon_pass.gif (deflated 9%) adding: Pictures/icon_reject_d.gif (deflated 13%) adding: Pictures/icon_reject.gif (deflated 15%) jim@hex:~/tmp/fixdoc/unpack$ zip -r ../Network\ Configuration\ 1.0.odt content.xml updating: content.xml (deflated 93%)