Open raginisahu opened 5 years ago
@raginisahu could you give me more info about the issue?
I have same problem. It works without error, but length of data
(on then
) is 0 and it creates a image file with zero bytes.
@AmirHossein @raginisahu i need more info about the operating system you are currently using and other global settings
Encountered the same problem using Ubuntu 18.04 subsystem for Windows running it with node v9.8.0 npm version 5.6.0
I am using Mac operating system with node js 11.13.0 .
@raginisahu @cristianbuta @AmirHossein have you already installed imagemagick and ghostscript successfully?
@Ng2k yes. Had no problems with the installation. Also used some different modules that had imagemagick as a dependency and it worked perfectly.
@cristianbuta @raginisahu @AmirHossein I've just found this post on stackoverflow. Here they explain how ImageMagick doesn't give permission to Ghostscript to manipulate pdf files, because there are security problems. You have to modify the Imagemagick policy.xml in order to read and write pdf files.
IMPORTANT: read carefully the security problems of ghostscript.
I hope this comment could be helpful for you. Alert us for everything else.
I am using ubuntu 8.04 .. getting no error in promise.. but only getting empty image
@Ng2k's suggestion based on the Stack Overflow link works for me, and I only had to change 1 line in /etc/ImageMagick-6/policy.xml
- <policy domain="coder" rights="none" pattern="PDF" />
+ <policy domain="coder" rights="read|write" pattern="PDF" />
This worked on Windows Subsystem for Linux with Node v12.18.0
I confirm the @nullromo solution works on Ubuntu 20.04 with node version v14.18.3
My guess is that if the pdf is password protected this library can't generate the thumbnail. Is that correct?
I still wonder how google can generate a preview of the 1st page or a password protected pdf and use it as thumbnail in the drive application. If one uploads a pdf to google drive, google is able to generate a thumbnail even though the pdf is password protected.
You have to change what @nullromo said.
Here's the sed command you can use if you're working in an automated environment :
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/' /etc/ImageMagick-6/policy.xml
const pdf = require('pdf-thumbnail'); const pdfBuffer = require('fs').readFileSync('/home/ragini/Desktop/front page.pdf');
pdf( pdfBuffer, /Buffer or stream of the pdf/ { crop: { width: 200, height: 400, x: 0, y: 0 } }) .then(data /Stream of the image/ => data.pipe(fs.createWriteStream(join('/home/ragini/Desktop', "preview", "previewBuffer.jpg")))) // ...
please give me solution.