Convert Word, Excel Files to PDF with PHP: A Comprehensive Guide
Introduction
Converting documents from various formats to PDF is crucial for combining files into a single document. This article will guide you through the process of converting Word and Excel files to PDF using PHP, without relying on the Zend Framework.
OpenOffice.org and PyODConverter
Conversion Script (adocpdf)
Create a plain text file named "adocpdf" containing the following script:
directory= filename= extension= SERVICE='soffice' if [ "`ps ax|grep -v grep|grep -c $SERVICE`" -lt 1 ]; then unset DISPLAY /usr/bin/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard & sleep 5s fi python /home/website/python/DocumentConverter.py /home/website/$directory$filename$extension /home/website/$directory$filename.pdf
PHP Function
Call the conversion function from your PHP script when encountering a Word / Excel file:
$output = array(); $return_var = 0; exec("/opt/adocpdf {$directory} {$filename} {$extension}", $output, $return_var);
Note:
The above is the detailed content of How Can I Convert Word and Excel Files to PDF Using PHP Without Zend Framework?. For more information, please follow other related articles on the PHP Chinese website!