[Python] Programmatically DOC/DOCX to PDF

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    I'm having an issue trying to convert DOC/DOCX to PDF programmatically. I'm following this answer.

    I'm using PyODConverter as mentioned in the answer above. I asked my web hosting to install OpenOffice and so they did, so when I ran whereis soffice it gave me /usr/bin/soffice.


    So, I have this piece of code:

    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);
    ?>

    My folder structure


    [​IMG]

    After executing my php code, the output is the following, being Array() the $output and 1 the $return_var

    Array ( ) 1


    I don't know much about python, and I really need this to work!

    Edit 1:


    I ran `exec('pydoc modules') and it gave me this output:

    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

    Continue reading...

Compartilhe esta Página