marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.55k stars 544 forks source link

DPI - Image Quality #250

Open hatpick opened 7 years ago

hatpick commented 7 years ago

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

frank-orellana commented 7 years ago

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", 
};
hatpick commented 7 years ago

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

frank-orellana commented 7 years ago

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.

hatpick commented 7 years ago

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

rickypaun commented 7 years ago

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

mtshare commented 6 years ago

+1

devtim123 commented 6 years ago

+1

chapmanio commented 5 years ago

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.

phtmgt commented 4 years ago

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

phtmgt commented 4 years ago

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.