I am using phantomjs node module. below is the link where from i get this module.
https://github.com/sgentle/phantomjs-node
this really work nice when i create a jpg image file from html. but its default "dpi" is 72 which is not good for printing the image file. so i want to set the dpi when i rendering the image.
from the above link i read some example like page.set('viewportSize', {width:640,height:480}). its set the image size perfectly. but i want to set dpi of image please guide me how can i achieve this.
var phantom = require('phantom');
phantom.create(function (ph) {
ph.createPage(function (page) {
page.open("http://www.google.com", function (status) {
page.render("bla.jpg");
ph.exit();
});
});
});
There are two ways.
You can use page.zoomFactor
to zoom the page. You have to increase the viewport size accordingly before changing the zoomFactor:
page.viewportSize = { width: 1600, height: 800 };
page.zoomFactor = 300.0/72.0;
page.render("zoom4.jpg");
If you are concerned with the quality, then render a pdf of the page. A pdf is vector-based and you can zoom in as much as you like. It works by using the pdf
extension when you give the filename to render
:
page.render("bla.pdf");
You can see how the rasterize.js example deals with the page sizes. There are some caveats though. You have to keep in mind to adjust the width of the rendered pdf. See for example this (unanswered) question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With