How to convert word to pdf using PHP in Linux, linuxpdf
How to convert word to pdf using PHP in Linux
1. Install libreoffice in ubantu
Sudo apt-get install libreoffice
2. Execute word to pdf on the command line
Convert cas.docx in the/home/wordToPdf/wordFiles/directory to a pdf file and store it in the/home/wordToPdf/pdfFiles directory:
Libreoffice -- headless -- convert-to pdf: writer_assist_export/home/wordToPdf/wordFiles/CAS.docx -- outdir/home/wordToPdf/pdfFiles
/Usr/share/fonts place Chinese fonts
Fc-cache-fv update font cache
Code executed in php
$ A = './doc/2.doc ';
$ B = './pdf ';
// $ Str = "libreoffice -- headless -- convert-to pdf: writer_pai_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/html/pdf";
Var_dump (system ($ str ));
Convert a Word document to a pdf file using php in linux
To use this tutorial, you need to install openoffice in linux. The detailed installation and usage tutorials are displayed on the change page.
(Examples of Converting office documents to pdf on linux platform (for programmers)).
Since, after reading this tutorial, you should not be able to deny linux permissions. Using php to convert Word documents to pdf documents requires a lot of permission settings. Therefore, I have granted 777 permissions to all directories and files used by php.
From this article (linux office document to pdf instance (programmer's dish), you can clearly understand the key code: (as follows)
Java-jar/usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar/tmp/1.doc/tmp/1.pdf
From the code above, we can see that php requires the read and write permissions of/tmp to use the java Command Execution permission.
View the java command location: which java
Assume that the location of the java command is/bin/java
Set the 777 permission for java: chmod 777/bin/java
Set permissions for the/tmp folder and the following files: chmod-R 777/tmp
After the permission is set. You can use the exec function of php to run the code: java-jar/usr/local/wenku/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar/tmp/1.doc/tmp/1.pdf
In the above Linux platform, the implementation of converting word to pdf using PHP is all the content that I have shared with you. I hope to give you a reference, and I hope you can provide more support to the customer's house.