PDFoundry icon indicating copy to clipboard operation
PDFoundry copied to clipboard

Implement onclick event handler

Open anthonyronda opened this issue 5 years ago • 4 comments

Is your feature request related to a problem? Please describe. I'm relatively happy with PDFoundry but I have a usecase to open a new door for System developers. I've always imagined a way to make a game's form fillable PDF sheet rollable in Foundry, and assumed it wasn't possible.

Describe the solution you'd like A PDF has a type of content (such as a PDF annotation) that, when clicked, emits an event that may be consumed by the system or another module. The event may include the text of the annotation as well as other data needed to pull nearby text input fields.

Additional context A PDF.js contributor suggests implementing this functionality directly to the PDF.js source to a user with a similar request https://github.com/mozilla/pdf.js/issues/9882#issuecomment-403588169

Describe alternatives you've considered If any come up I'll be sure to provide additional guidance.


I'm invested in this idea, so I plan to put in the research and hope to contribute code if I'm successful at finding a working solution.

anthonyronda avatar Nov 28 '20 05:11 anthonyronda

Hey @rondaa Thanks for your interest in this, it's one of the more significant features I would like to get to, but my time is incredibly sparse lately.

Ideally I would like to make this usable from the end user's perspective. Click handlers are great and all but it's a much more limited feature than end user based editable buttons, which would be my ideal.

You can examine the way I emit a few of the existing events, there might be a way for you to capture a click event.

Djphoenix719 avatar Nov 28 '20 16:11 Djphoenix719

Thanks so much for your thoughtful reply!

One way to enable a GM user to make clickable "buttons" is to allow users to make annotations in PDF.js, instead of just viewing them. PDF.js doesn't support annotation editing, but options exist (you can incorporate pdfAnnotate library functions in PDF.js, for example). I think annotations are a great option because users can make them in their own PDF viewer (outside of foundry) and then upload them without owning a PDF editor. PDF annotations can be customized to any style you (or the user) wants.

There are other ways, though that's my best lead so far.

If you or anyone reading this wants to discuss ideas for this on Discord, my DMs are open at corporat#1282.

anthonyronda avatar Nov 28 '20 21:11 anthonyronda

PDF annotations sound like a good way to explore. I would only worry that they may require editing the PDF, and you can not guarantee that you have write access because of things like S3 buckets. If you can extract the annotation data that library you mentioned creates and store it in Foundry that would be ideal, then it could be recreated at runtime.

The other thing that would have to be explored is the compatibility of that library with PDFjs. PDF is an insanely large file format specification with dozens of often conflicting rules. There's a real chance PDFjs doesn't support or partially supports all this library can do, even if I know it supports "annotations".

Those are my two large concerns. If you want to look into them we can go from there together based on your findings. With an extra set of hands I can probably dedicate a bit of time, as I don't have to do everything myself.

Djphoenix719 avatar Nov 28 '20 22:11 Djphoenix719

Also note my fork of PDFjs is here.

Djphoenix719 avatar Nov 28 '20 22:11 Djphoenix719