简体   繁体   English

如何将 HTML 坐标转换为 PDF 坐标(pdf-lib,javaScript)

[英]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.我需要做的是将png图像拖动到某个坐标并使用pdf-lib将此图像插入PDF文档中。 But I've found out that the pdf coordinates are not the same as the HTML coordinates.但我发现 pdf 坐标与 HTML 坐标不同。 Is there a way to convert HTML mouse coordinates into PDF coordinates?有没有办法将 HTML 鼠标坐标转换为 PDF 坐标? I'm rendering this PDF using iframe.我正在使用 iframe 渲染这个 PDF。

Thanks in advance for any helpful information.提前感谢您提供任何有用的信息。

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.好的,对于将来需要它的任何人,我现在都得到了答案:在 pdf-lib 中,使用的是点而不是像素。 Points are mostly 72dpi and that is almost 1 inch.点大多是 72dpi,几乎是 1 英寸。 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.像素比 72dpi 大 0.75 倍(实际上更小,但由于相乘而更大),因此您需要做的是将鼠标坐标(或其他)乘以 0.75。 Then you need to adjust the offset and you are good to go.然后你需要调整偏移量,你对 go 很好。 Hope someone find this useful.希望有人觉得这很有用。

it seems this question is too hard for mankind, I seached a fix to this issue in vain around two weeks.似乎这个问题对人类来说太难了,我在两周左右的时间里徒劳地寻找了一个解决这个问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM