How to use PHP to turn word to PDF in the Linux platform
1, Ubantu under the installation of LibreOffice
sudo apt-get install LibreOffice
2. Command line to perform word to PDF
Convert the Cas.docx in the/home/wordtopdf/wordfiles/directory into a PDF to the/home/wordtopdf/pdffiles directory:
LibreOffice--headless--convert-to Pdf:writer_pdf_export/home/wordtopdf/wordfiles/cas.docx--outdir/home/ Wordtopdf/pdffiles
/usr/share/fonts delegation of Chinese fonts
FC-CACHE-FV Updating font Caches
Code that executes in PHP
$a = './doc/2.doc '; $b = './pdf ';//$str = "LibreOffice--headless--convert-to pdf:writer_pdf_export./doc/2.doc--outdir. /pdf ";//$str = ' ls '. /'; $str = "Export home=/tmp && libreoffice--headless-convert-to pdf/var/www/html/doc/2.doc-outdir/var/www/ht Ml/pdf "; Var_dump (System ($STR));
Using PHP in Linux to convert Word documents to PDF
Use this tutorial to install OpenOffice in Linux, with detailed installation and use tutorials in the page
(aLinux platform Office document to a PDF instance (Programmer's dish)).
Now that you have read the tutorial, you should not deny that Linux has a very deceptive authority. Using PHP to convert Word documents to PDF documents requires a lot of permission settings. So here I give PHP 777 permissions for directories and files.
From this article (the Linux Platform Office document to PDF instance (Programmer's dish)) It is clear to know the key code: (below)
Java-jar/usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/1.doc /tmp/1.pdf
From the above code, PHP to use the Java command Execution permissions, and/tmp to read and write permissions.
To view the location of the Java command: which Java
Assume that the location of the Java command is:/bin/java
To set 777 permissions for Java: chmod 777/bin/java
Set permissions for the/tmp folder and the following files: Chmod-r 777/tmp
After you have set permissions. You can run the code using the EXEC function of PHP:
Java-jar/usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /tmp/1.doc /tmp/1.pdf