Recently, I want to add a function in our data center website(Which is only Chinese version now, an English version is preparing): “output the geographic metadata to openoffice odt format”. So, the odtphp project came into my sight.
After download the 1.0.1 version, and try some tests in its code. There is no problem in the text replacing, but if I insert into the odt file an image, the OpenOffice (What I use is LibreOffice) always tell me this file need repair, although the repair result nice. Dig into another search, find this problem and solution in the author’s blog.
Use the latest version (1.3) in the author’s blog, this bug is disappeared.
There is another requirement in my site yet, maybe it is not a problem: The image file which is dynamic produced has not a extension in the url, So the code in odtphp: setImage must change its behavior here.
So I patched the code, and released it here (it’s GPL license):
wlx@wlxpc:~$ diff odf.php odtphp-1.0.1_modified_files/odf.php
> $filename = strtok(strrchr($value, '/'), '/.');
> $file = substr(strrchr($value, '/'), 1);
< //$this->file->addFile($imageKey, 'Pictures/' . $imageValue);
< $this->file->addFromString('Pictures/' . $imageValue,file_get_contents($imageKey));
> $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
In short, what I do: change the filenmae to a hash string (md5(source)), and save it with file_get_contents function (which could parse the url).
And, a big Thanks to you and your odtphp project: Vikas Mahajan.
Download patch file: odf.php.patch