vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
730 stars 178 forks source link

[Question] Is it possible to make placeholder-pdfkit works with Buffer #256

Open zentetsukenz opened 5 months ago

zentetsukenz commented 5 months ago

Objective I would like to migrate from using the placeholder-plain to placeholder-pdfkit.

The reason is that the placeholder-plain still depends on the older version of placeholder-pdfkit010 which unfortunately, rely on older version of "crypto-js": "^3.1.9-1".

Migrating from the plain to the pdfkit would allow my application to rely on the newer version of the crypto-js.

What I've tried I've tried replicate how the placeholder-plain make use of the placeholder-pdfkit010 (by creating a pdfKitMock object), but with the placeholder-pdfkit instead. Unfortunately, it doesn't work.

My guess is that PDFkit 0.11 works differently from the 0.10. Hence, simply copy the way how plain version works won't make the 0.11 work magically.

So Do you have any suggestion or recommendation on how to make this works? I'm happy to open a PR but would like to hear from you first (any guidance would be very appreciated 🙏 ).

The only alternative way I can think of Simply change placeholder-plain dependency to placeholder-pdfkit but, yeah, I think I have to deal with PDFKit 0.10 -> PDFKit 0.11 breaking changes.

vbuch commented 5 months ago

Hi. I'd always imagined that it should be possible to upgrade from pdfkit 10 to newer versions. But to provide the correct mocking object would require understanding how 11+ works internally really. That's a bad chain of dependencies really. I think what we are using from PDFKit is generally the understanding of references and object encoding...

zentetsukenz commented 5 months ago

I think I found another alternative, simply override pdfkit peer dependency just work.

package.json

  "overrides": {
    "@signpdf/placeholder-plain": {
      "pdfkit": "^0.15.0"
    }
  }

And to anyone happen to read this decide to use this method, probably a good idea to test your use cases and lock a pdfkit version.