pdf-thumbnail icon indicating copy to clipboard operation
pdf-thumbnail copied to clipboard

showing blank jpeg image.

Open raginisahu opened this issue 5 years ago • 13 comments

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.

raginisahu avatar Aug 09 '19 16:08 raginisahu

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

nicofuccella avatar Sep 23 '19 20:09 nicofuccella

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 avatar Sep 24 '19 12:09 AmirHossein

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

nicofuccella avatar Sep 24 '19 18:09 nicofuccella

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

iamcrisb avatar Oct 09 '19 14:10 iamcrisb

I am using Mac operating system with node js 11.13.0 .

raginisahu avatar Oct 18 '19 02:10 raginisahu

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

Ng2k avatar Oct 20 '19 16:10 Ng2k

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

iamcrisb avatar Oct 20 '19 17:10 iamcrisb

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

Ng2k avatar Oct 20 '19 19:10 Ng2k

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

shivarajnaidu avatar May 14 '20 07:05 shivarajnaidu

@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

nullromo avatar Dec 28 '20 21:12 nullromo

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

minhna avatar Feb 23 '22 05:02 minhna

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.

redeemefy avatar Feb 04 '23 18:02 redeemefy

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

RiedelNicolas avatar Mar 29 '23 13:03 RiedelNicolas