|All requests||>||Convert Microsoft Word doc, docx to PDF||>||Request new recommendation||>||Featured requests||>||No recommendations|
by Andsraj - 6 years ago (2015-08-08)
Please suggest any solution to convert a Microsoft Word document file to a PDF file using a PHP script.
6. by Samuel Adeshina - 6 years ago (2015-08-10) Reply
I agree with Manuel, using libreoffice also depends on what you need the solution for. If it's meant for the public, i don't think it's such a very good idea.
1. by Manuel Lemos - 6 years ago (2015-08-09) Reply
I don't think there is a solution to do that directly.
What exists are some classes that generate PDF from HTML.
Eventually it may be possible to convert Word documents to HTML or even save the Word documents as HTML.
So you may combine the two solutions to achieve your final result. Would that work for you?
2. by Andsraj - 6 years ago (2015-08-09) in reply to comment 1 by Manuel Lemos Comment
Thanks for your reply. Kindly suggest how can we convert doc file to html and It should be same format as in doc file like (bold, font style, etc.)
3. by Andsraj - 6 years ago (2015-08-09) in reply to comment 2 by Andsraj Comment
I searched and found this is possible means doc to pdf using libreoffice. please give me the steps to convert it. It can be for windows and linux server also.
Thanks in advance.
4. by Manuel Lemos - 6 years ago (2015-08-09) in reply to comment 2 by Andsraj Comment
There are classes to convert Microsoft Word to HTML but they use COM objects. That means that you need to be running PHP on Windows.
An alternative solution would be to call some Web service API that actually perform that conversion. There are some that perform that service, but most that I see, they charge for the API access although some allow a free trial period.
Another solution would be to parse the DOCX file which is basically a ZIP file with XML of the Word document inside and try to rebuild the document as far as possible.
I don't know a class that does this but could be an innovative idea to solve the problem.
5. by Manuel Lemos - 6 years ago (2015-08-09) in reply to comment 3 by Andsraj Comment
I think it may be possible to convert files with libreoffice but you need to have it installed in the machine you are using.
Usually that requires Linux X-Windows GUI (Gnome or KDE) installed. Do you think you can install that on your server?
7. by Axel Hahn - 6 years ago (2015-08-16) in reply to comment 5 by Manuel Lemos Comment
Using libreoffice for converting does not need X environment. I use Libreoffice (requires java on your server too)
/usr/bin/lowriter --headless --convert-to pdf [infile]
This means: for each conversion it starts a new process. It is OK to convert a few docs. Otherwise search for a daemon mode of libreoffice.
I wrote a PHP class to act as a spooler + converter to handle files, queuing and cleanup. But to convert a function with an exec is enough.
8. by Manuel Lemos - 6 years ago (2015-08-16) in reply to comment 7 by Axel Hahn Comment
You are right, when you use the --headless paramter, it does not require X-Windows.
That spooler converter class is interesting. I am sure it would help many people that need to convert many documents. It would be great if you could submit it.
You can convert DOCX files to PDF using single line of code. No configuration needed.
1. by Reza - 6 years ago (2016-05-10) Reply
How does it work. Can you please explain