php - Programatically DOC/DOCX to PDF -
i'm having issue trying convert doc/docx pdf programatically. i'm following this answer.
i'm using pyodconverter mentioned in answer above. asked web hosting install openoffice , did, when ran whereis soffice
gave me /usr/bin/soffice
.
so, have piece of code:
adocpdf
filename=$1 extension=$2 service='soffice' if [ "`ps ax|grep -v grep|grep -c $service`" -lt 1 ]; 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); ?>
my folder structure
after executing php code, output following, being array()
$output
, 1
$return_var
array ( ) 1
i don't know python, , need work! time , help!
edit 1:
i ran `exec('pydoc modules') , gave me output:
please wait moment while gather list of 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 _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
i have asked hosting provider install latest libreoffice , worked out ok!
i'm using following code:
exec("/opt/libreoffice4.0/program/soffice.bin --headless --convert-to pdf --outdir ".$path." ".$filename.".".$extension, $output, $return_var);
i'm using uploadify upload document convert , i'm giving file client download.
hope question/answer helps else in world me, had trouble openoffice.
Comments
Post a Comment