Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showing blank jpeg image. #4

Open
raginisahu opened this issue Aug 9, 2019 · 13 comments
Open

showing blank jpeg image. #4

raginisahu opened this issue Aug 9, 2019 · 13 comments
Labels

Comments

@raginisahu
Copy link

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
Copy link
Owner

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

@AmirHossein
Copy link

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
Copy link
Owner

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

@iamcrisb
Copy link

iamcrisb commented Oct 9, 2019

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

@raginisahu
Copy link
Author

I am using Mac operating system with node js 11.13.0 .

@Ng2k
Copy link
Collaborator

Ng2k commented Oct 20, 2019

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

@iamcrisb
Copy link

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

@Ng2k
Copy link
Collaborator

Ng2k commented Oct 20, 2019

@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
Copy link

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

@nullromo
Copy link

@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
Copy link

minhna commented Feb 23, 2022

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

@redeemefy
Copy link

redeemefy commented Feb 4, 2023

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants