Recently I was working on odtPHP to generate OpenOffice.org writer (.odt) file on the fly using PHP. I was using lastest version (1.0.1) of odtPHP. But I found a bug in software. Whenever I try to insert images in the document (specially in a segment), I was getting warning by OpenOffice (3.x) that the resultant file is corrupted and asks to repair document or not. Sometimes this warning can occur if your template is not correctly formated but I verified that this problem also exists with tutorial 5 present in odtPHP package (tested on Ubuntu 10.04 with OpenOffice 3.2). Although the document repaired by OpenOffice is perfectly fine, but it seems unusual and awkward to people. Also this bug seems to me as a big stone in a smooth path as I can’t be able to convert odt to pdf on the fly using any available tools. The reason is that as the resultant file is corrupted all available tools fail to load/open the document. As said by some great personality “Necessity is the Mother of Invention”, I tried to solve the problem and got success. Below is the reason of problem and solution:
Reason of Problem (bug):-
As I tested the odtPHP software with OpenOffice 3.x, I found that OpenOffice keeps the record of all files present in .odt archieve file in the manifest.xml file present under META-INF directory. You can open OpenOffice .odt file with any archive manager to see files present under the document. You must find the above said file there.
Now the problem with odtPHP 1.0 is that it only modifies content.xml file and does not edit manifest.xml file. So, when your odt document (generated by odtPHP) contains images, it means you are increasing the number of files in the archive without informing the OpenOffice about their type, path etc. in the manifest.xml file. This has resulted to the corrupted document warning upon opening the file.
Solution of above Bug:-
I have modified odf.php and Segment.php files (present in the library directory of odtPHP package) so that they also modify manifest.xml file to add information about images. You can download these files as zip package from the following link-:
Download odtPHP-1.0.1 from odtPHP official website-:
Extract the zip archive and replace the original files (in the library directory) with these files. Now try again the tutorial 5 present in tests directory of odtPHP, you will find that now OpenOffice opens the downloaded file without any warning. If still you are getting corrupt file warning, feel free to ask me.
Replacing tags in header/footer:-
Also, odtPHP version (1.0.1) does not support replacing tags in header or footer sections of document. It requires the editing of styles.xml file of OO template. So, recently I modified odf.php file so that it also replaces tags with text in header or footer sections odt document just it does for body section of the document. Also, now images information is added in manifest.xml file according to extension of image (for compatibility with future releases of OO).🙂