プログラムで DOC/DOCX を PDF に変換しようとすると問題が発生します。私はこの答えに従っています。
上記の回答で述べたように、私はPyODConverterを使用しています。Webホスティングに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
index.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()
なり$output
ます1
。$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