I have highcharts-export-server v2.1.0 (which uses phantomjs v.2.1.1) configured on 2 servers.
Problem: One server can produce a chart from my "test" .json to .svg, the other server cannot / seems stuck...
Question: I have already set the logLevel to 4, How else can I debug this / find the error?
.
My input script is the following:
{"title":{"text":"Benchmark +0.75% (Year to Date)"},"time":{"useUTC":false},"chart":{"alignThresholds":true,"width":1000,"height":400,"plotBackgroundColor":null,"plotBorderWidth":0,"plotShadow":false,"spacingRight":40},"xAxis":{"labels":{"rotation":-45}},"yAxis":[{"labels":{"format":"{value:.0f}"},"showLastLabel":true,"opposite":false,"min":-3.67256505,"max":4.93075599694519,"tickPositions":[-3.67,-2.6,-1.52,0,0.63,1.7,2.78,3.86,4.93]},{"showLastLabel":true,"gridLineWidth":0,"tickPosition":"outside","labels":{"align":"right","x":30,"style":{"color":"#ff0000"}},"min":-0.9340809915870241,"max":1.2540895500000002,"tickPositions":[-0.93,-0.66,-0.39,-0.11,0,0.16,0.43,0.71,0.98,1.25]}],"legend":{"enabled":true},"rangeSelector":{"enabled":false},"scrollbar":{"enabled":false},"navigator":{"enabled":false},"credits":{"enabled":false},"plotOptions":{"series":{"compare":"percent","showInNavigator":false}},"series":[{"compare":"amount","data":[[1609282800000,0],[1609369200000,-0.03428646532872559],[1609455600000,-0.0016039750283303178],[1609714800000,0.7637526405996908],[1609801200000,0.8005732883660022],[1609887600000,-0.1690494144598209],[1609974000000,-0.3809350266101741],[1610060400000,-1.514325071693856],[1610319600000,-0.4765023006985114],[1610406000000,-0.20592306146072215],[1610492400000,-1.6056700749591757],[1610578800000,-2.283907756098269],[1610665200000,-2.8475657141212585],[1610924400000,-2.5301565339659216],[1611010800000,-1.347913879404139],[1611097200000,-1.078254441804205],[1611183600000,-1.508647334728952],[1611270000000,-1.5661224299388987],[1611529200000,-2.280813980426055],[1611615600000,-1.9904069262878465],[1611702000000,-3.1733261828598924],[1611788400000,-2.6038661425901943],[1611874800000,-3.10474672552985],[1612134000000,-1.9489382228070617],[1612220400000,-1.4168123948971045],[1612306800000,-1.5077205238559155],[1612393200000,-1.114743473256452],[1612479600000,-1.445007216058669],[1612738800000,-1.2708019773828516],[1612825200000,-1.5637751417799883],[1612911600000,-0.9207988194119499],[1612998000000,-0.5330477534657541],[1613084400000,-1.3483873661346957],[1613343600000,-1.2824277237734494],[1613430000000,-0.8192853328358063],[1613516400000,-0.3653079990091568],[1613602800000,-0.060653517166342485],[1613689200000,0.8697340876174797],[1613948400000,1.2280953226873725],[1614034800000,1.0859394764373809],[1614121200000,1.2063367293352778],[1614207600000,0.10773414212172927],[1614294000000,-1.5207190905506263],[1614553200000,-0.9816998314673975],[1614639600000,-0.924383129032802],[1614726000000,-0.8715904396361718],[1614812400000,-0.4280745420743859]],"name":"Portfolio -0.43%"},{"compare":"amount","data":[[1609282800000,0],[1609714800000,0.8278755650112268],[1609801200000,0.7356135496841887],[1609887600000,-0.3448445224439989],[1609974000000,-0.5651564695949629],[1610060400000,-1.6946417469431263],[1610319600000,-0.6017716353404978],[1610406000000,-0.302437374178699],[1610492400000,-1.6516136459999498],[1610578800000,-2.459423156169538],[1610665200000,-2.696698045145274],[1610924400000,-2.410809781870449],[1611010800000,-1.3613816021318614],[1611097200000,-0.991919709902811],[1611183600000,-1.414545878781237],[1611270000000,-1.4817771059954743],[1611529200000,-2.3322008861873744],[1611615600000,-2.036590278127237],[1611702000000,-3.4976807891963],[1611788400000,-2.986102839764737],[1611874800000,-3.4540325607614886],[1612134000000,-2.105269707267987],[1612220400000,-1.5899676921416361],[1612306800000,-1.7726301025414615],[1612393200000,-1.5556279775712611],[1612479600000,-1.7695269895245613],[1612738800000,-1.655544008265486],[1612825200000,-1.93170951416185],[1612911600000,-1.2587762893416121],[1612998000000,-0.8789710996493616],[1613084400000,-1.718017623965562],[1613343600000,-1.6160328512600741],[1613430000000,-1.1553433147096226],[1613516400000,-0.8357362895423104],[1613602800000,-0.5901872577077749],[1613689200000,0.4652404389007492],[1613948400000,0.7387166627010888],[1614034800000,0.6296984147131646],[1614121200000,0.597220732990178],[1614207600000,-0.45944804378783566],[1614294000000,-1.952809940009137],[1614553200000,-1.430060618679485],[1614639600000,-1.3313860807479094],[1614726000000,-1.3636570533070103],[1614812400000,-1.622445786457749],[1614898800000,-1.5049462738540242],[1615158000000,-1.1762370313930126]],"name":"BENCHM REF -1.18%"},{"data":[[1609282800000,0],[1609714800000,-0.064122924411536],[1609801200000,0.06495973868181348],[1609887600000,0.17579510798417797],[1609974000000,0.18422144298478882],[1610060400000,0.1803166752492702],[1610319600000,0.12526933464198642],[1610406000000,0.09651431271797684],[1610492400000,0.04594357104077407],[1610578800000,0.17551540007126887],[1610665200000,-0.1508676689759847],[1610924400000,-0.11934675209547274],[1611010800000,0.013467722727722453],[1611097200000,-0.08633473190139407],[1611183600000,-0.09410145594771491],[1611270000000,-0.08434532394342442],[1611529200000,0.05138690576131921],[1611615600000,0.046183351839390596],[1611702000000,0.3243546063364078],[1611788400000,0.3822366971745428],[1611874800000,0.3492858352316386],[1612134000000,0.15633148446092537],[1612220400000,0.1731552972445316],[1612306800000,0.264909578685546],[1612393200000,0.4408845043148091],[1612479600000,0.3245197734658922],[1612738800000,0.38474203088263437],[1612825200000,0.3679343723818618],[1612911600000,0.33797746992966227],[1612998000000,0.34592334618360754],[1613084400000,0.36963025783086634],[1613343600000,0.33360512748662474],[1613430000000,0.3360579818738163],[1613516400000,0.4704282905331536],[1613602800000,0.5295337405414324],[1613689200000,0.40449364871673055],[1613948400000,0.4893786599862837],[1614034800000,0.4562410617242163],[1614121200000,0.6091159963450998],[1614207600000,0.5671821859095649],[1614294000000,0.43209084945851073],[1614553200000,0.4483607872120876],[1614639600000,0.4070029517151075],[1614726000000,0.4920666136708385],[1614812400000,1.1943712443833632]],"color":"#ff0000","name":"Relative Performance +0.75%","yAxis":1,"compare":"amount","dashStyle":"ShortDash"}]}
This is the code I use to produce the .svg file
/opt/mx/reports/node_modules/highcharts-export-server/bin/cli.js -infile /opt/mx/reports/js/_testcases/stock.json -outfile /tmp/_teststockchart.svg -type svg -constr StockChart --logLevel 4
This is the .svg being produced:
I am developing application where user can upload some drawings in pdf format. Uploaded files are stored on S3. After uploading, files has to be converted to images. For this purpose I have created lambda function which downloads file from S3 to /tmp folder in lambda execution environment and then I call ‘convert’ command from imagemagick.
convert sourceFile.pdf targetFile.png
Lambda runtime environment is nodejs 4.3. Memory is set to 128MB, timeout 30 sec.
Now the problem is that some files are converted successfully while others are failing with the following error:
{ [Error: Command failed: /bin/sh -c convert /tmp/sourceFile.pdf
/tmp/targetFile.png convert: %s' (%d) "gs" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=/tmp/magick-QRH6nVLV--0000001" "-f/tmp/magick-B610L5uo"
"-f/tmp/magick-tIe1MjeR" # error/utility.c/SystemCommand/1890.
convert: Postscript delegate failed/tmp/sourceFile.pdf': No such
file or directory # error/pdf.c/ReadPDFImage/678. convert: no images
defined `/tmp/targetFile.png' #
error/convert.c/ConvertImageCommand/3046. ] killed: false, code: 1,
signal: null, cmd: '/bin/sh -c convert /tmp/sourceFile.pdf
/tmp/targetFile.png' }
At first I did not understand why this happens, then I tried to convert problematic files on my local Ubuntu machine with the same command. This is the output from terminal:
**** Warning: considering '0000000000 XXXXX n' as a free entry.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.10.5 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
So the message was very clear, but the file gets converted to png anyway. If I try to do convert source.pdf target.pdf and after that convert target.pdf image.png, file is repaired and converted without any errors. This doesn’t work with lambda.
Since the same thing works on one environment but not on the other, my best guess is that the version of Ghostscript is the problem. Installed version on AMI is 8.70. On my local machine Ghostsript version is 9.18.
My questions are:
Is the version of ghostscript problem? Is this a bug with older
version of ghostscript? If not, how can I tell ghostscript (with or
without using imagemagick) to repair or ignore errors like it does on
my local environment?
If the old version is a problem, is it possible to build ghostscript
from source, create nodejs module and then use that version of
ghostscript instead the one that is installed?
Is there an easier way to convert pdf to image without using
imagemagick and ghostscript?
UPDATE
Relevant part of lambda code:
var exec = require('child_process').exec;
var AWS = require('aws-sdk');
var fs = require('fs');
...
var localSourceFile = '/tmp/sourceFile.pdf';
var localTargetFile = '/tmp/targetFile.png';
var writeStream = fs.createWriteStream(localSourceFile);
writeStream.write(body);
writeStream.end();
writeStream.on('error', function (err) {
console.log("Error writing data from s3 to tmp folder.");
context.fail(err);
});
writeStream.on('finish', function () {
var cmd = 'convert ' + localSourceFile + ' ' + localTargetFile;
exec(cmd, function (err, stdout, stderr ) {
if (err) {
console.log("Error executing convert command.");
context.fail(err);
}
if (stderr) {
console.log("Command executed successfully but returned error.");
context.fail(stderr);
}else{
//file converted successfully - do something...
}
});
});
You can find a compiled version of Ghostscript for Lambda in the following repository.
You should add the files to the zip file that you are uploading as the source code to AWS Lambda.
https://github.com/sina-masnadi/lambda-ghostscript
This is an npm package to call Ghostscript functions:
https://github.com/sina-masnadi/node-gs
After copying the compiled Ghostscript files to your project and adding the npm package, you can use the executablePath('path to ghostscript') function to point the package to the compiled Ghostscript files that you added earlier.
Its almost certainly a bug, or perhaps limitation, with the older version of Ghostscript.
Many PDF producers create PDF files which do not conform to the specification, and yet will open without complain in Adobe Acrobat. Ghostscript endeavours to do the same, but obviously we can't know what Acrobat is going to allow, so we are continually chasing this nebulous target. (FWIW that warning is a legitimate out-of-spec PDF file).
There's nothing you can do with the old version other than replace it.
Yes you can build Ghostscript from source, I have no idea about a nodejs module, not sure why that's relevant.
There are numerous other applications which will render a PDF file, MuPDF is another one I know of. And, of course, you can use Ghostscript directly without using ImageMagick. Of course, if you can load another application, then you should simply be able to replace your Ghostscript installation too.
The version of GS on aws is an old version with known bugs. We can get around this by uploading an x64 GS file, compiled specifically for Linux. Then upload that using new AWS lambda layers. I have written a node function that does just this here:
https://github.com/rcastoro/PDFImagine
Make sure you have that GS layer for your lambda, however!