Hopding / pdf-lib

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

Library produces different results in browser vs nodejs #1589

Open laszlo1337 opened 8 months ago

laszlo1337 commented 8 months ago

What were you trying to do?

Generate PDF with svg path

How did you attempt to do it?

Implemented code in JS fiddle, where it works perfectly https://jsfiddle.net/5avk4jwd/

What actually happened?

The same code ported to nodejs produces entirely different results - the SVG is drawn in a wrong position and drawing rectangle actually results in rectangle being over the SVG path, even though it's drawn earlier like in above example

correct result from the browser: https://github.com/foliojs/pdfkit/files/13943064/4282dfc2-f3f1-4399-9ec4-191e59185540.pdf wrong result from nodejs: https://github.com/foliojs/pdfkit/files/13943074/2SFtR3p2.pdf

correct browser result if bg enabled: https://github.com/foliojs/pdfkit/files/13943189/8b7edae8-0a0c-412d-8fa9-4412d5963b9d.pdf invalid nodejs result: https://github.com/foliojs/pdfkit/files/13943180/5Hl7kt4n.pdf

What did you expect to happen?

Produce the same output as in the browser

How can we reproduce the issue?

https://jsfiddle.net/5avk4jwd/ - the code is here. paste the same code in NodeJS environment

Version

1.17.1

What environment are you running pdf-lib in?

Browser, Node

Checklist

Additional Notes

This is the exact same issue that's happening in pdfkit library, where I aleady created an issue https://github.com/foliojs/pdfkit/issues/1490 the produced pdf results are exact same - wrong svg placement and wrong draw order.

important: edits

EDIT: I solved the wrong placement issue - turns out that was the fault of invalid path. But ordering issue still prevails

EDIT2: Perhaps the layering issue it not really what it seems. Now to me it looks like instead of my SVG path the function draws and strokes the previous rectangle shape. I tried looking for any reset, path end etc related functions in pdflib api but nothing works