node-pdf-image icon indicating copy to clipboard operation
node-pdf-image copied to clipboard

Convert pdf to png error

Open g3umesh opened this issue 6 years ago • 3 comments

Am seeing below error when converting pdf to png: { pdfFilePath: '/mnt/c/content/upload/test.pdf', pdfFileBaseName: 'test', convertOptions: { '-density': '300' }, convertExtension: 'png', useGM: false, combinedImage: false, outputDirectory: '/mnt/c/content/upload' } Error { message: 'Failed to convert page to image', error: { Error: Command failed: convert -density 300 "/mnt/c/content/upload/test.pdf[0]" "/mnt/c/content/upload/test-0.png" convert: no images defined /mnt/c/content/upload/test-0.png' @ error/convert.c/ConvertImageCommand/3210.

at ChildProcess.exithandler (child_process.js:276:12)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:915:16)
at Socket.stream.socket.on (internal/child_process.js:336:11)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at Pipe._handle.close [as _onclose] (net.js:561:12)
 killed: false,
 code: 1,
 signal: null,
 cmd: 'convert -density 300 "/mnt/c/content/upload/test.pdf[0]" "/mnt/c/content/upload/test-0.png"' },

stdout: 'Unrecoverable error: typecheck in .bind\nOperand stack:\n --nostringval-- typecheck --nostringval-- currentglobal .currentglobal\n', stderr: 'convert: no images defined /mnt/c/content/upload/test-0.png\' @ error/convert.c/ConvertImageCommand/3210.\n' }

Below are the commands that are available after installing imagemagick, ghostscript, poppler-utils (in Linux). Should ImageMagick and Ghostscript be a specific version for this to work? `umeshg:/mnt/c/content/upload$ convert -version Version: ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28 http://www.imagemagick.org Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC Features: DPC Modules OpenMP Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

umeshg:/mnt/c/content/upload$ gs -version GPL Ghostscript 9.25 (2018-09-13) Copyright (C) 2018 Artifex Software, Inc. All rights reserved. umeshg:/mnt/c/content/upload$ pdfinfo -v pdfinfo version 0.41.0 Copyright 2005-2016 The Poppler Developers - http://poppler.freedesktop.org Copyright 1996-2011 Glyph & Cog, LLC`

g3umesh avatar Nov 08 '18 15:11 g3umesh

@g3umesh I had been fighting with this bug for several days. The only way I found to avoid it (not fix actually) is to use the GraphicsMagick library. Any up-to-date updates of ImageMagick or GhostScript did help at all. You have to install it first via apt-get install graphicsmagick and then provide an option to the PDFImage class constructor like that:

const pdfImage = new PDFImage(filePath, {
  graphicsMagick: true,
});

Hope it'll help you

pkantsedalov avatar Dec 04 '18 13:12 pkantsedalov

thanks :) it worked.

akashgaur-kiwi avatar Feb 08 '19 14:02 akashgaur-kiwi

How to fix it with node.js App?

memeteli avatar Mar 03 '20 13:03 memeteli