537mfb has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks

I have recently been given the task of creating an online tool to compare the text on two files. Problem is that not all files will be text files - some may be docx some doc etc.

So i started my task - done everything needed for the compare of two text files (including upload to the server running the perl CGI) and all is well.

Now it's time to handle when the uploaded file is not a plain text file. And problems arise.

At first i tried running LibreOffice via open with the convert-to command line option - that works well outside CGI mode but under CGI mode i can't execute LibreOffice (due to privilege restrictions to the server i guess) - the script just dies with no error message.

Then i looked into Win32::OLE, but the server is Linux and that module is Windows only.

Then i looked into OpenOffice::UNO but i can't find any information on that for perl and i have tried it on python and same happens as with running LibreOffice - works well in normal mode but move it to CGI and loadComponentFromURL makes the script die with no message

Anyone has any other way to achieve this? is it at all possible to do? Any help would be appreciated

Replies are listed 'Best First'.
Re: Convert documents in CGI
by Corion (Patriarch) on Jun 21, 2011 at 18:44 UTC

    The closest to document conversion is OpenOffice / LibreOffice in command line mode, and/or antiword (which can't handle docx due to its age). I suggest that you have *Office running as a daemon script that looks in a drop directory for files to convert, and have the CGI script submit new conversion jobs to it, and fetch the results.

      Yes - i have been looking into the LibreOffice option - like i mentioned

      not sure how to make it run as daemon and keep looking in the drop directory - can't be every X minutes cause it need to output the result on upload and not x minutes later but will look into that now

      maybe keep a perl script ran as root running in the background (not CGI), checking the folder and when new file is found execute the converter - will see

      thanks for the reply

        Well, I got this problem solved.

        Case anyone needs a hint on a similar problem, what i did was use a socket server script over TCP using use IO::Socket::INET and having it always on running as root, and it handles requests to convert files from the CGI script that in this case is a client.

        Thank you for the help.