February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728
  1. We welcome any feedback, questions or comments

How to convert word document/powerpoint file to pdf or jpg on LINUX

Here are the quick work around to convert.odc/.ppt to image or pdf file.

We need the following packages installed on the server,
a. openoffice
b. imagemagick
c. Java

Installing openoffice

#yum install openoffice.org*
#yum install ImageMagick*

How to verify imagemagick is installed and working

[root@rc-170 ~]# convert logo: logo.gif
[root@rc-170 ~]# convert –version
Version: ImageMagick 6.2.8 04/17/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC

Downloading jodconverter from sourceforge

#wget http://downloads.sourceforge.net/project/jodconverter/JODConverter/2.2.2/jodconverter-2.2.2.zip?use_mirror=nchc
#unzip jodconverter-2.2.2.zip
#mv jodconverter-2.2.2 /usr/local/jodconverter/ ( optional)

Verify the java installed

[root@rc-170 ~]# java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)

Now we need to run openoffice as a service. So we can create a init script for this. A sample scripts can be download from here

#vi /etc/init.d/openofficed

#!/bin/bash
OOo_HOME=/usr/lib64/openoffice.org
SOFFICE_PATH=$OOo_HOME/program/soffice
PIDFILE=$OOo_HOME/openoffice-server.pid

case “$1″ in
start)
if [ -f $PIDFILE ]; then
echo “OpenOffice headless server has already started.”
exit
fi
echo “Starting OpenOffice headless server”
$SOFFICE_PATH -headless -accept=”socket,host=127.0.0.1,port=8100;urp;” -nofirststartwizard & > /dev/null 2>&1
touch $PIDFILE
;;
stop)
if [ -f $PIDFILE ]; then
echo “Stopping OpenOffice headless server.”
killall -9 soffice && killall -9 soffice.bin
rm -f $PIDFILE
exit
fi
echo “Openoffice headless server is not running, foo.”
exit
;;
*)
echo “Usage: $0 {start|stop}”
exit 1
esac
exit 0

In this script I found the open office installation for was different according to the OS architecture. Since my OS is 64 bit it will be “/usr/lib64/openoffice.org” else it is “/usr/lib/openoffice.org” on Linux box.

[root@s15351481 ~]# vi /etc/rc.local then add the line “/etc/init.d/opeofficd start”

# java -jar /usr/local/jodconverter/lib/jodconverter-cli-2.2.2.jar document.ppt mam.pdf
You may use to call it from php using the “exec” funcation.
exec(‘java -jar /usr/local/jodconverter/lib/jodconverter-cli-2.2.2.jar/lib/jodconverter-cli-2.2.2.jar document.doc mam.pdf’);

This program will support for the following conversions,
1. DOC —> PDF
2. DOC —> ODT
3. DOC —> RTF
4. XLS —> PDF
5. XLS –> ODS
6. XLS –> CSV
7. PPT –> PDF
8. PPT —> ODP
9. PPT —> SWF
10. ODT –> PDF
11. ODT —> DOC
12. ODT —> RTF
13. ODS —> PDF
14. ODS —> XLS
15. ODS —> CSV
16.ODP —> PDF
17. ODP —> PPT
18. ODP —> SWF

How do I solve this error ?

[root@rc-040 installation]# /usr/lib/openoffice.org/program/soffice “-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager” -nologo -headless -nofirststartwizard
/usr/lib/openoffice.org/program/soffice.bin X11 error: Can’t open display:
Set DISPLAY environment variable, use -display option
or check permissions of your X-Server
(See “man X” resp. “man xhost” for details)
[root@rc-040 installation]#

Yoy may need Xserver started on the server. I started the vnc server and execute the service script. Only this method will work.

/etc/init.d/openofficed start

How to check openoffice service is running,

We can test it either by telnet to the listening port or grep it from the process list.

[root@rc-040 ~]# <strong>telnet localhost 8100</strong>
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
`ufffdufffd'com.sun.star.bridge.XProtocolPropertiesUrpProtocolPropertiesO>?
AufffdD+ufffdXufffdu0771ufffdFqufffdu055d
^]
[root@rc-040 ~]# <strong>netstat -nlp| grep ":8100"</strong>
tcp        0      0 127.0.0.1:8100              0.0.0.0:*                   LISTEN      21278/soffice.bin
[root@rc-040 ~]#
Author: Liju Mathew
Visit Liju's Website - Email Liju
I'm Liju, one linux enthusiastic who have been playing with Linux for more than 7 years. I'm curious about to read blog, learning and implementing new technologies from my personal experience. Like to be play with burning head on busy schedule :-) This is a bookmark of all challenges that I'd faced which would be helpful to others sometimes as I'd learn it from the same way :-) Nothing more, I have to go miles, before I sleep

3 comments to How to convert word document/powerpoint file to pdf or jpg on LINUX

  • Thanks for this article!

    I noticed your article title says convert to .JPG or .PDF, but in the content of your article, “.JPG” is never mentioned, and none of the conversions listed are to .JPG ( i.e. “This program will support for the following conversions…”)

    How could we get these files to be .JPG?

  • Fabar

    Your title says “convert to JPEG” but it seems that the openoffice server cannot convert to image files, just to PDF and some others… Am I missing something? Thank you

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>