This firebase function should take a pdf in /test/testfile.pdf, convert it to grey and save it somewhere. I want to use this function in a more complicated process, but the exec('convert') is really not helping me.
The issue is the 'exec' command keeps failing. In the shell, the exact command line you see here is working:
convert -colorspace GRAY -density 300 test/testfile.pdf /tmp/out.pdf
The error in the logs is this:
{ ChildProcessError: Command failed: convert -colorspace GRAY -density 300 test/testfile.pdf /tmp/out.pdf convert: no images defined `/tmp/out.pdf' @ error/convert.c/ConvertImageCommand/3210. `convert -colorspace GRAY -density 300 test/testfile.pdf /tmp/out.pdf\` (exited with error code 1) at callback (/user_code/node_modules/child-process-promise/lib/index.js:33:27) at ChildProcess.exithandler (child_process.js:205:5) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:920:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5) name: 'ChildProcessError', code: 1, childProcess: { ChildProcess: { [Function: ChildProcess] super_: [Object] }, fork: [Function], _forkChild: [Function], exec: [Function], execFile: [Function], spawn: [Function], spawnSync: [Function: spawnSync], execFileSync: [Function: execFileSync], execSync: [Function: execSync] }, stdout: '', stderr: 'convert: no images defined `/tmp/out.pdf\' @ error/convert.c/ConvertImageCommand/3210.\n' }
This is the function:
const functions = require('firebase-functions');
const rp = require('request-promise');
const request = require('request');
const baseURL = "https://www.google.com/cloudprint/"
const exec = require('child-process-promise').exec;
const mkdirp = require('mkdirp-promise');
const path = require('path');
const os = require('os');
const fs = require('fs');
exports.convertPDF = functions.https.onRequest((req, res) => {
const tempLocalThumbFile = path.join(os.tmpdir(), "out.pdf");
try {
let tempLocalFile = "test/testfile.pdf"
exec('convert -colorspace GRAY -density 300 test/testfile.pdf '+tempLocalThumbFile).then((a) => {
console.log('Conversion created at', tempLocalThumbFile);
}, function (err) {
console.log(err)
})
} catch(err) {
console.log(err)
}
})
I am pretty stuck. How to get this convert to work in Firebase Functions?