pdfjs icon indicating copy to clipboard operation
pdfjs copied to clipboard

Capability of adding javascript action and named openAction

Open ZhengZhang98 opened this issue 3 years ago • 1 comments

Hi, Thanks for this library!

I'm looking for a feature of popping up the print dialog when the document is opened. This seems to be possible by adding the javascript action or the namedAction. However, I didn't see an api in this library dealing with the js/named actions. I'm wondering if this is a valid feature request.

There is a way I could see for this feature to work without changing the basic working flow of your lib:

  • For adding the javascript action: Referencing to pdf specification-7.7.4 Name Dictionary, it is possible to add the javascript actions similar to the destination, by having a new entry(/Javascript [jsNameTree]) in the document's name dictionary.
  • For adding the named action triggered when the document is opened, there are two steps:
    1. Write the action dictionary entries specific to named actions (referencing to pdf specification-12.6.4.11 Named Actions). The structure is quite simple based on the doc.
    2. Trigger the named action when the document is opened. This can be implemented by associated the named action dictionary to the /OpenAction entry in the catalog dictionary. (referencing to pdf specification-7.7.2 Document Catalog)

Do you think the above solution can be implemented? If this sounds to be a feasible solution, I'd love to work on it and open a pull request to add the apis as doc.javascript() and doc.namedOpenAction().

ZhengZhang98 avatar Dec 08 '20 20:12 ZhengZhang98

Hi, it sounds like something worth adding, and I think it can be down like you described it. It would probably also help supporting use-cases like https://github.com/rkusa/pdfjs/issues/235. Since, I personally don't have a use-case for this, a PR would be welcome!

rkusa avatar Dec 28 '20 10:12 rkusa