stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
474 stars 181 forks source link

ngx-extended-pdf-viewer Adding Image annotation #2547

Closed mathewsnamanda closed 3 weeks ago

mathewsnamanda commented 3 weeks ago

I would like to know how I can add my custom parameter into the object of Image PdfImageParameters. The reason is i want to be able to set either BitmapImageid or simply add my custom id so that I can be able to pass it to an API for storage to database.

Thank you

stephanrauh commented 3 weeks ago

As far as I know, you can't. Your use-case makes sense to me, so I'd like to support it, but I'm afraid that's beyond my abilities. I've inherited the image annotation API from @Calixteman, and to be honest, I sort of hacked it to enable Angular developers to add stamp annotations to PDF files. Experience shows I have to be careful about which API I modify. If I guess wrong, the PDF viewer develops in another direction than I guessed, and I'm in merge hell.

So I'm very careful about modifying the core pdf.js library. The annotation editor seems to be an API that's still under development, so every extension of mine might break without notice. So I won't implement your feature, even though it makes sense to me.

But you can kindly ask @Calixteman. Maybe it is possible - or he can make it possible - to add extra parameters to annotations that survive saving and loading the PDF file?

calixteman commented 3 weeks ago

Can't you just override https://github.com/mozilla/pdf.js/blob/master/src/display/editor/stamp.js#L754 and https://github.com/mozilla/pdf.js/blob/082ad955f03dbc4ea60d2d27f9ffb900c027887e/src/core/annotation.js#L4887 ? Usually we don't add something we don't use because having to maintain something we don't use can be hard, time consuming and too much constraining (i.e. could not let us make the modifications we want for Firefox)

stephanrauh commented 3 weeks ago

Thanks a lot for chiming in! Yes, that sounds like a working approach.

@mathewsnamanda It's still beyond my scope, but at least now it sounds like an achievable task. Can I talk you into sending me a pull request? I'lll happily guide you, it's just that at the moment, I'm too busy to implement such a feature myself. How do you like the idea?

mathewsnamanda commented 3 weeks ago

It is a good one, let us give it a try

stephanrauh commented 3 weeks ago

And you can read it after saving and loading the PDF file?

mathewsnamanda commented 3 weeks ago

Yeah, sure because I have got several images, and I want to be able to add them and at least link them to their local image using id