Converting Pdf pages into images in nodeJS using pdf2img module - node.js

I am trying to convert Pdf pages into images using the pdf2img module.My code is as follows..
var pdf2img = require('pdf2img');
var input = __dirname + '/pd.pdf';
pdf2img.setOptions({
type: 'png', // png or jpeg, default png
size: 410, // default 1024
density: 200, // default 600
outputdir: __dirname + '/output' // mandatory, outputdir must be absolute path
});
pdf2img.convert(input, function(info) {
console.log(info);
});
I am getting following error after running above code..
C:\node\app>node conv.js
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn pdfinfo ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)

pdf2img is using pdfinfo for the pdf library.
From pdfinfo's homepage:
Requires
Node.js
npm node package manager
xpdf / pdfinfo(1)
So download and install Xpdf on your windows computer, and you will hopefully get rid of the ENOENT error.

Related

Impossible to install spookyjs

I want to install spookyjs and find it impossible to do so. I've tried three different ways:
Run the standard spookyjs package.json provided in spookyjs github.
Then I try to run hello.js and I am greeted with this error.
C:\Users\User1\Desktop\test2>node hello.js
events.js:183
throw er; // Unhandled 'error' event
^
Error: spawn casperjs ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
Installed phantomjs and casperjs globally and package.json installed spooky and tiny-jsonrpc. I get the same error message.
Installed these dependencies from package.json
"dependencies": {
"spooky": "^0.2.5",
"tiny-jsonrpc": "^2.0.1",
"phantom": "^4.0.12",
"casperjs": "^1.1.4"
I get the same error.
I came across this link:
Issue
and it detailed the solution. That is this chunk of code:
const
path = require('path'),
_ = require('underscore')
;
var
// close env to pass to spawn
env = _.clone(process.env),
// get the PATH - in my local Windows, it was Path
envPath = env.PATH || env.Path,
// get path to node_modules folder where casperjs and
// phantomjs-prebuilt are installed
// this will be different for you
binDir = path.join(__dirname, './../../node_modules/.bin'),
Spooky = require('spooky')
;
// update the path in the cloned env
env.PATH = env.Path = `${envPath};${binDir}`;
var spooky = new Spooky({
child: {
// spooky is trying to call casperjs.bat for windows
// .bat doesn't work, so call the update .cmd file
// this fixes issue 2 with the file
command: /^win/.test(process.platform) ? 'casperjs.cmd' : 'casperjs',
transport: 'http' ,
spawnOptions: {
// set the env using cloned version
// this fixes issue 1 with the path
env: env
}
},
...
So now the program runs without an error. Actually though it runs without anything, because while on the one hand no error pops up, on the other nothing pops up. I debbuged by putting console.log() inside spooky's callback function but nothing is displayed. That is for another question though...
But the error i was receiving has vanished and the interpreter runs the code.

pdf2img in node js giving a error 'identify' is not recognized as an internal or external command

var fs = require('fs');
var pdf2img = require('pdf2img');
var input = __dirname+'\\public\\pdfs\\User.pdf';
pdf2img.setOptions({
type: 'png', // png or jpeg, default png
size: 1024, // default 1024
density: 600, // default 600
outputdir: __dirname+'\\public\\pdfs', // mandatory, outputdir must be absolute path
targetname: 'test' // the prefix for the generated files, optional
});
pdf2img.convert(input, function(err, info) {
if (err) console.log(err)
else console.log(info);
});
After running this i'm getting following error :
'identify' is not recognized as an internal or external command,
operable program or batch file.
child_process.js:508
throw err;
^
Error: Command failed: identify -format %n C:\Users\pr326323\Pictures\samp\public\pdfs\User.pdf
'identify' is not recognized as an internal or external command, operable program or batch file.
at checkExecSyncError (child_process.js:465:13)
at execSync (child_process.js:505:13)
at async.waterfall.pages (C:\Users\pr326323\Pictures\samp\node_modules\pdf2img\lib\pdf2img.js:47:32)
at fn (C:\Users\pr326323\Pictures\samp\node_modules\pdf2img\node_modules\async\lib\async.js:638:34)
at Immediate._onImmediate (C:\Users\pr326323\Pictures\samp\node_modules\pdf2img\node_modules\async\lib\async.js:554:34)
at processImmediate [as _immediateCallback] (timers.js:383:17)
Assuming that you have Ubuntu system. You also have to install Dependency for this library. Run following command:
sudo apt-get install graphicsmagick

Why I cannot run this super simple resizing an image code with gm node package?

here is my whole code:
var fs = require('fs')
, gm = require('gm');
// resize and remove EXIF profile data
gm('./image.jpg')
.resize(240, 240)
.noProfile()
.write('./image2.jpg', function (err) {
if (!err) { console.log('done') } else { console.log(err); } ;
});
I have also installed imageMagick.
But when I run that simple code I get this silly error:
Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "./image.jpg" "-resize" "240x240" "+profile" "\"*\"" "./image2.jpg" this most likely means the gm/convert binaries can't be found
at ChildProcess.<anonymous> (C:\Users\ali\Desktop\Node js\Uploader\node_modules\gm\lib\command.js:232:12)
at emitOne (events.js:96:13)
at ChildProcess.emit (events.js:188:7)
at ChildProcess.cp.emit (C:\Users\ali\Desktop\Node js\Uploader\node_modules\cross-spawn\lib\enoent.js:36:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
I have also gone ahead into imageMagick website and download and install imageMagick.(ImageMagick-7.0.4-6-Q16-x64-dll.exe HTTP)
and this is my project structure:
My project structure
That is all! Would U please tell me where is the problem?

"Error: spawn /usr/bin/compass ENOENT" when using gulp-compass

I'm attempting to run the following Gulp task to compile Sass files, using the plugin, gulp-compass on OS X Yosemite 10.5.5.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
However, when I try to run the task like gulp compile2013Base, I get the following error:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32)
at child_process.js:1144:20
at process._tickCallback (node.js:355:11)
I already have compass installed at /usr/bin/compass, and running compass in the terminal does not show any errors.
I'm not sure what to go on here, how do I get the error details?
This is helped me
sudo gem install -n /usr/local/bin compass
see Error: "compass:dist" Fatal error: spawn /usr/bin/compass ENOENT

Nodejs GM module ImageMagick - strange Error

I have a very strange error. I'm using MAC OS X 10.9.5.
When i use some functions from GM (npm install gm) like resize or something else i got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
I have found many threads about it and according to them i have installed graphicksmagic and imagemagick with brew to system.
brew install imagemagick
brew install graphicsmagick
It was working for a while but for no reason it starts to showing the above error again.
I checked that i have installed imagemagick and graphicksmagick in system and its working from terminal.
I checked if i have it in $PATH and its there.
If i run this in nodejs it shows correct version of imagemagick in console, so i assume path is ok in nodejs.
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
if(error)
sys.puts(error);
if(stderr)
sys.puts(stderr);
sys.puts(stdout);
}
exec("identify --version", puts);
This is code which is crashing:
gm(request(url), thumbName)
.resize('300', '300', '^')
.gravity('Center')
.crop('300', '300')
.toBuffer('JPG',function (err, buffer) {
var data = {
Bucket: bucket,
Key: thumbName,
Body: buffer,
ACL:'public-read',
ContentType: 'image/jpeg'
};
s3.putObject(data, function(err, res) {
....
});
Everything is working when i deploy it on heroku
IF someone will have this issue i solved it.
I add variable PATH to enviroment variables in node with this value
bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin

Resources