1

currently I am working on an automatic docx2pdf converter in node.js. I am using unoconv. When i run this command in the shell in works pretty well:

unoconv -f pdf "/opt/bitnami/apache2/htdocs/123.docx"

But i want to call this command from node.js, there are some modules (unoconv wrapper), but none of this worked for me. So i just want to call this command from above. I tried all solutions from node.js shell command execution but they dont work.
Why does this code snippet doesent work for me?

                        function run_cmd(cmd, args, callBack) {
                        var spawn = require('child_process').spawn;
                        var child = spawn(cmd, args);
                        var resp = "";

                        child.stdout.on('data', function(buffer) {
                            resp += buffer.toString()
                        });
                        child.stdout.on('end', function() {
                            callBack(resp)
                        });
                    } // ()
                    run_cmd("unoconv", ['-f pdf "/opt/bitnami/apache2/htdocs/123.docx"'], function(text) {
                        console.log(text)
                    });

It dont produced output even if i run the script from pm2 as service or directly with the node command. I hope you can help me! Thanks in advance

Community
  • 1
  • 1
t333o
  • 39
  • 5
  • I suggest you also listen to `child.stderr.on("data"...` and `child.on("close"...` to see if you get any clues to what might be wrong. – Hampus Oct 03 '16 at 10:45
  • @Hampus ok thanks i got an new Error: Fatal Python error: Py_Initialize: Unable to get tImportError: No module named 'encodings' . but why does this appear only when calling the command from node and not from command line? – t333o Oct 03 '16 at 11:16
  • Try printing which version of python you run on the command line with `python --version`, then do the same from within node. – Hampus Oct 03 '16 at 11:57
  • @Hampus python-version commandline: 2.7.11 and from node also Python 2.7.11. - same with python3 || Do you have another idea? – t333o Oct 03 '16 at 12:41
  • I'm guessing but there might be a problem with the python path when using it from node's context, and therefore it doesn't find the encodings module. – Hampus Oct 03 '16 at 13:47

1 Answers1

0

I suspect that command you use just creates a new PDF file alongside with DOCX one. If you want to have it in node you probably should try --stdout flag.

Like this:

unoconv -f pdf --stdout "/opt/bitnami/apache2/htdocs/123.docx"

teq
  • 1,494
  • 1
  • 11
  • 12