How to convert word to pdf using PHP in Linux, linuxpdf

Source: Internet
Author: User
Tags tmp folder

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)


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.

Related Article

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: 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.