Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.6k stars 635 forks source link

Having problem with SVG path #1578

Open jaysridhar opened 7 months ago

jaysridhar commented 7 months ago

What were you trying to do?

It appears that the positive direction of y-axis in pdf-lib is down rather than up as per pdf spec. Is this correct? Or am I doing something wrong.

How did you attempt to do it?

In the snippet below, I am drawing a horizontal line at the bottom of the pdf at -2 units. Next I draw a vertical line at x=100. But to get the vertical line upwards, I have to specify a y of -100. It does not work if I specify y=100. Is this supposed to be how it works?

let svgStr = 'M 0,-2 L 1000,-2 M 100,-2 l 0,-100'
      page.drawSvgPath(svgStr, {
        x: 0,
        y: 0,
        color: rgb(1.0, 0, 0),
        borderWidth: 2
      })

What actually happened?

A vertical line from bottom to top should be y=100. Instead it works only if I specify y=-100.

What did you expect to happen?

I expected the line to be drawn from bottom to up when y = 100

How can we reproduce the issue?

https://jsfiddle.net/crispduty/spmvwdtk/17/

Version

1.17

What environment are you running pdf-lib in?

Browser

Checklist

Additional Notes

No response

ZiarayZ commented 5 months ago

If this was "fixed" svg paths would be drawn upside down... This is just a difference between svgs and pdf in my opinion.