Search code examples
javascriptpdfiframe

How to convert HTML coordinates into PDF coordinates(pdf-lib, javaScript)


what I need to do is dragging png image to some coordinates and inserting this image into PDF document using pdf-lib. But I've found out that the pdf coordinates are not the same as the HTML coordinates. Is there a way to convert HTML mouse coordinates into PDF coordinates ? I'm rendering this PDF using iframe.

Thanks in advance for any helpful information.


Solution

  • Okay, I got the answer now for anyone who will need this in the future: in pdf-lib there are used points instead of pixels. Points are mostly 72dpi and that is almost 1 inch. Pixels are 0.75 times bigger(actually smaller but bigger because of multiply) than 72dpi so what you need to do is multiply mouse coordinates(or whatever) by 0.75. Then you need to adjust the offset and you are good to go! Hope someone find this useful.