Use PHP to share Word to PDF under Linux

Source: Internet
Author: User
Tags tmp folder
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.