Opening multiple html files in PhantomJs via PHP throws syntax error -
i want php script call phantomjs command line, generate muliple pdf's out of many html files. have concatenated string paths html files, , next invoke exec command :
$myfile1 = dirname(__file__)."/testfile0.html"; $myfile2 = dirname(__file__)."/testfile1.html"; $myfile3 = dirname(__file__)."/testfile2.html"; $files = array($myfile1, $myfile2, $myfile3); $command = 'phantomjs '.dirname(__file__).'/render.js '.implode('|', $files); exec($command, $phantomout); echo print_r($phantomout); when i'm calling 'phantomjs render.js "file1.html|file2.html"' works fine. but, when trying php script i'm getting following error in apache error_log:
testfile1.html: line 1: syntax error near unexpected token `<' testfile1.html: line 1: `<!doctype html... the html files i'm using fine, i'm out of ideas on can cause this. output when running script in browser : array ( ) 1 instead of text i'm getting in command line.
below phantomjs rendering script :
var page = require('webpage').create(), addresses = phantom.args[0], outputpath = '/path_to_pdf/', outputfilename, filesarray, outputarray = [], loadinprogress = false, pageindex = 0, interval; page.viewportsize = { width: 600, height: 600}; if(addresses.indexof('|') !== -1){ filesarray = addresses.split('|'); } else{ filesarray = [addresses]; } interval = setinterval(function() { if (!loadinprogress && pageindex < filesarray.length) { page.open(filesarray[pageindex]); } if (pageindex === filesarray.length) { console.log('output: ', outputarray.join('|')); phantom.exit(); } }, 250); page.onloadstarted = function() { loadinprogress = true; }; page.onloadfinished = function() { loadinprogress = false; outputfilename = 'print'+pageindex+'.pdf'; page.render(outputpath+outputfilename); outputarray.push(outputfilename); pageindex++; }
have tried wrapping paths files after implode inside quotation ? looks invalid parameter me, although error strange.
Comments
Post a Comment