Recently i came across a requirement to convert a wide range of file formats (.doc, docx, .xls, .rtf , .odt, .ods, .ppt etc.) to pdf file in PHP.
I found a very good utility to do this, which i would like to share with you all.
Note: You need to have OpenOffice and unoconv installed for this.
unoconv is a command line utility that can convert any file format that OpenOffice can import, to any file format that OpenOffice is capable of exporting.
Some of the supported document formats are Open Document Format (.odt), MS Word (.doc), MS Office Open/MS OOXML (.xml), Portable Document Format (.pdf), HTML, XHTML, RTF, Docbook (.xml), and more.
Vist http://dag.wieers.com/home-made/unoconv/ to get a complete list of file formats supported by unoconv for conversion
Link to download OpenOffice: http://www.openoffice.org/
Link to download unoconv: http://dag.wieers.com/home-made/unoconv/#download
Command for installation of unoconv in Linux Ubuntu:
sudo apt-get install unoconv
The command line syntax to convert various files is :
unoconv -f file_format source_file
Example:
php code to convert file1.doc to file1.pdf:
Batch conversion:
It can also be used to convert a batch of files at a time.
CLI To convert all ODT files in a location to Word DOC format:
unoconv -f doc path_to_location/*.odt