pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Convert pixels in 1/72 inches

Open stasmotorny opened this issue 1 year ago • 3 comments

What are you working on?

Hi, guys. I am working on documents signature implementation. It have few steps:

  1. User see PDF file and should tap on the place where signature should be placed. On this step I'm using https://github.com/wonday/react-native-pdf this library to display document and take tap's coordinates.
  2. After step 1 I navigate user to the screen where he should draw his signature.
  3. After user draw signature I'm using pdf-lib drawImage() method to sign document.

There is few problems in this approach:

  1. 0, 0 coordinates from react-native-pdf are in top left corner and as I understand coordinates are in pixels.
  2. pdf-lib as I found out is using 1/72 inch as measurements units and 0, 0 point is in bottom left corner.

As result I can sign the document but with wrong placement of signature. So I need some way to properly convert coordinates taken from react-native-pdf to coordinates that are used by pdf-lib to place signature. I already tried a lot of variants but no one works fine. In current implementation I'm using formula like this: (pageHeight - signatureCoords.y) / (160 * PixelRatio.get()) / 72 So maybe someone can give me an advice how to properly place signature in PDF?

Additional Notes

No response

stasmotorny avatar Apr 01 '23 21:04 stasmotorny

Hi, any positive progress with this feature? I'm currently struggling with the same problem

matheusPcruz18 avatar May 23 '23 14:05 matheusPcruz18

Hi, I'm having the same problem as the first two guys, does anyone have a solution yet?

JohnLopen avatar Jan 08 '24 16:01 JohnLopen

I am also struggling with the same issue. I want the user to drag an image on the pdf page, and on the confirm button insert the image on that location. I have values in terms of left and right of the absolute positioned image but when they are given as x and y of the drawImage method, it just disappears.

ziaKhan1995 avatar Apr 02 '24 06:04 ziaKhan1995