nicofuccella / pdf-thumbnail

npm package to create the preview of a pdf file
MIT License
29 stars 7 forks source link

showing blank jpeg image. #4

Open raginisahu opened 5 years ago

raginisahu commented 5 years ago

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.

nicofuccella commented 5 years ago

@raginisahu could you give me more info about the issue?

AmirHossein commented 5 years ago

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.

nicofuccella commented 5 years ago

@AmirHossein @raginisahu i need more info about the operating system you are currently using and other global settings

iamcrisb commented 5 years ago

Encountered the same problem using Ubuntu 18.04 subsystem for Windows running it with node v9.8.0 npm version 5.6.0

raginisahu commented 5 years ago

I am using Mac operating system with node js 11.13.0 .

Ng2k commented 5 years ago

@raginisahu @cristianbuta @AmirHossein have you already installed imagemagick and ghostscript successfully?

iamcrisb commented 5 years ago

@Ng2k yes. Had no problems with the installation. Also used some different modules that had imagemagick as a dependency and it worked perfectly.

Ng2k commented 5 years ago

@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.

shivarajnaidu commented 4 years ago

I am using ubuntu 8.04 .. getting no error in promise.. but only getting empty image

nullromo commented 3 years ago

@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

minhna commented 2 years ago

I confirm the @nullromo solution works on Ubuntu 20.04 with node version v14.18.3

redeemefy commented 1 year ago

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.

RiedelNicolas commented 1 year ago

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