mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

Printing to PDF using nodejs #115

Closed zdila closed 5 years ago

zdila commented 5 years ago

Hello,

Is there a way to pring map to PDF with specified page format using nodejs bindings? So far I am only able to render a square tile to PDF which is always 3.56 × 3.56 inch with:

map.zoomToBox([2386323, 6216456, 2406828, 6231940]);
map.renderFile('/home/john/map.pdf', { format: 'pdf', buffer_size: 256, scale_denominator: 1500, scale: 0.2 }, cb);

I've found something for python but I already use nodejs.

zdila commented 5 years ago

Actually I can adjust PDF dimensions by setting it in mapnik.Map constructor but I am not sure if this is correct approach comparable to the implementation in python.

talaj commented 5 years ago

Hi!

Mapnik is rendering PDF using Cairo backend. Cairo is using device-independent coordinates called user-space, where 1 point is 1/72 of inch (cairo-pdf-surface-create(), also see Point_(typography)). PDF format is using the same coordinates. This is why you get 3.56 inch ~ 256 / 72.

Actually I can adjust PDF dimensions by setting it in mapnik.Map constructor but I am not sure if this is correct approach comparable to the implementation in python.

Yes, this is correct approach, but you have to keep in mind that you are not working with pixels in case of PDF output.

zdila commented 5 years ago

Thanks for the valuable info. It still seems that python API offers somewhat more features than nodejs (like PDF margins,...), but I think I can use what I have now :-)