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

DPI - Image Quality

Open hatpick opened this issue 8 years ago • 10 comments
trafficstars

What's the default dpi value? Is it configurable? My images have bad quality, I was wondering if that's the problem.

hatpick avatar Mar 13 '17 08:03 hatpick

From the documentation:

 "quality": "75",           // only used for types png & jpeg

you can change that by passing that property in the options object:

const options = {
        quality: "100", 
};

frank-orellana avatar Mar 13 '17 19:03 frank-orellana

How's quality (0-100) gets translated to dpi?!

hatpick avatar Mar 13 '17 20:03 hatpick

It doesn't... if you really need to set a custom dpi you can set it directly in the options object (it gets passed completely to the phantom executable so it should work that way)

const options = {
        quality: "100", 
        dpi: 300
};

Otherwise you will have to look through phantom documentation on how to set it and edit the pdf_a4_portrait.js file to send the option. But if your problem is that your images have bad quality setting the quality property should be enough.

frank-orellana avatar Mar 13 '17 21:03 frank-orellana

In my experiments, quality doesn't make any difference, btw I had it set to 100, I too read the documentation!

hatpick avatar Mar 13 '17 22:03 hatpick

@frank-orellana Hi! Can you explain me how to do that? I need set a custom DPI. It works only for images? PDF?

rickypaun avatar Jun 08 '17 22:06 rickypaun

+1

mtshare avatar Sep 07 '17 14:09 mtshare

+1

devtim123 avatar Nov 17 '17 14:11 devtim123

The quality setting is only relevant when you set the "type" option as "png" or "jpeg".

I haven't found a way (yet) of increasing the image quality - but it really is awful.

chapmanio avatar Mar 08 '19 13:03 chapmanio

Similar situation here. Anyone figured out a way to somehow force DPI?

phtmgt avatar Apr 15 '20 15:04 phtmgt

I think I found a solution. Not sure which one made the difference:

  1. Set the dpi to 300
  2. Set image size (e.g., height or width) to half the original dimension (height or width) to get 'retina' quality image

I set these both and the images now come out crystal clear. I hope it helps someone.

phtmgt avatar Apr 15 '20 15:04 phtmgt