1

我在尝试以编程方式将 DOC/DOCX 转换为 PDF 时遇到问题。我正在关注这个答案

我正在使用上面答案中提到的PyODConverter 。我要求我的虚拟主机安装OpenOffice,他们也这样做了,所以当我运行whereis soffice它时,它给了我/usr/bin/soffice.


所以,我有这段代码:

adocpdf

filename=$1
extension=$2
SERVICE='soffice'
if [ "`ps ax|grep -v grep|grep -c $SERVICE`" -lt 1 ]; then 
unset DISPLAY
/usr/bin/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard & 
sleep 5s
fi
python /home/[MYSITE]/public_html/docpdf/DocumentConverter.py /home/[MYSITE]/public_html/docpdf/$filename$extension /home/[MYSITE]/public_html/docpdf/$filename.pdf

索引.php

<?php
    $filename = "teste";
    $extension = ".doc";
    $output = array();
    $return_var = 0;

    exec("/home/[MYSITE]/public_html/docpdf/adocpdf {$filename} {$extension}", $output, $return_var);
    print_r($output);
    print($return_var);
 ?>

我的文件夹结构

在此处输入图像描述

执行我的php代码后,输出如下,Array()$output1$return_var

Array ( ) 1

我对python不太了解,我真的需要这个来工作!

编辑1:

我运行了 `exec('pydoc modules') 它给了我这个输出:

Please wait a moment while I gather a list of all available modules...

ArrayPrinter audioop iniparse (package) select
BaseHTTPServer audit inspect selinux (package)
Bastion auparse itertools semanage
CDROM avc japanese (package) seobject
CGIHTTPServer base64 keyword sepolgen (package)
CORBA bdb kudzu sets
Canvas binascii lapack_lite sgmllib
ConfigParser binhex ldap (package) sha
Cookie bisect ldapurl shelve
DLFCN bonobo (package) ldif shlex
Dialog bsddb (package) libiscsi shm
DocXMLRPCServer bz2 libsvn (package) shutil
DocumentConverter cElementTree libuser signal
FFT (package) cPickle libxml2 site
FileDialog cStringIO libxml2mod smtpd
FixTk cairo (package) linecache smtplib
HTMLParser calendar linuxaudiodev snack
IN cgi locale sndhdr
LinearAlgebra cgitb logging (package) socket
M2Crypto (package) chunk macpath sos (package)
MA (package) cmath macurl2path sqlite (package)
MLab cmd mailbox sqlitecachec
Matrix code mailcap sre
MimeWriter codecs markupbase sre_compile
Numeric codeop marshal sre_constants
ORBit collections math sre_parse
PortableServer colorsys md5 stat
Precision commands mhlib statcache
Queue compileall mimetools statvfs
RNG (package) compiler (package) mimetypes string
RandomArray cookielib mimify stringold
ScrolledText copy mmap stringprep
SimpleDialog copy_reg modulefinder strop
SimpleHTTPServer cracklib multiarray struct
SimpleXMLRPCServer crypt multifile subprocess
SocketServer csv mutex sunau
StringIO curses (package) netrc sunaudio
TYPES datetime new svn (package)
Tix dbhash nis symbol
Tkconstants dbm nntplib symtable
Tkdnd dbus (package) ntpath sys
Tkinter decimal nturl2path syslog
UserArray difflib numeric_version tabnanny
UserDict dircache oddjob tarfile
UserList dis opcode telnetlib
UserString distutils (package) operator tempfile
_LWPCookieJar dl optik termios
_MozillaCookieJar doctest optparse test (package)
__builtin__ dogtail (package) os textwrap
__future__ drv_libxml2 os2emxpath this
_audit dsextras ossaudiodev thread
_bisect dsml pango threading
_bsddb dumbdbm pangocairo time
_codecs dummy_thread parser timeit
_codecs_cn dummy_threading pdb timing
_codecs_hk elementtree (package) pickle tkColorChooser
_codecs_iso2022 email (package) pickletools tkCommonDialog
_codecs_jp encodings (package) pipes tkFileDialog
_codecs_kr errno pkgutil tkFont
_codecs_tw exceptions platform tkMessageBox
_csv fcntl popen2 tkSimpleDialog
_curses filecmp poplib toaiff
_curses_panel fileinput posix token
_gamin fnmatch posixfile tokenize
_heapq formatter posixpath trace
_hotshot fpformat pprint traceback
_kudzu ftplib profile tty
_ldap gamin pstats turtle
_locale gc pty types
_multibytecodec gconf pwd tzparse
_numpy gdbm py_compile umath
_random getopt pyclbr unicodedata
_semanage getpass pydoc unittest
_snack gettext pyexpat urlgrabber (package)
_socket glob pygtk urllib
_sqlite gnome (package) pynche (package) urllib2
_sqlitecache gnomevfs (package) quopri urlparse
_sre gobject (package) random user
_ssl gopherlib ranlib uu
_strptime grp re warnings
_symtable gtk (package) readline wave
_testcapi gtkunixprint reconvert weakref
_threading_local gzip regex webbrowser
_tkinter heapq regex_syntax whichdb
_weakref hmac regsub whrandom
acutil hotshot (package) repr xdrlib
aifc htmlentitydefs resource xml (package)
anydbm htmllib rexec xmllib
array httplib rfc822 xmlrpclib
arrayfns idlelib (package) rgbimg xxsubtype
asynchat ihooks rhpl (package) yum (package)
asyncore imageop rlcompleter zipfile
atexit imaplib robotparser zipimport
atk imghdr rpm (package) zlib
atspi imp rpmUtils (package)
audiodev imputil sched
4

1 回答 1

3

我已经要求我的托管服务提供商安装最新的 LibreOffice,结果一切正常!

我正在使用以下代码:

exec("/opt/libreoffice4.0/program/soffice.bin  --headless --convert-to pdf --outdir ".$path."  ".$filename.".".$extension, $output, $return_var);

我正在使用 Uploadify 上传要转换的文档,然后将文件返回给客户端进行下载。

希望这个问题/答案可以帮助世界上像我一样遇到 OpenOffice 问题的其他人。

于 2013-04-11T14:06:52.753 回答