Skip to content
Discussion options

You must be logged in to vote

You have to set OpenAction to a JS action dictionary object.
This is currently not implemented as such in PyMuPDF.
But it should be possible to achieve your goal using PyMuPDF low-level interface calls. Approach could be along the lines:

  1. Add an object defining the JS action
  2. Access the PDF catalog and add the OpenAction key pointing to the JS action dictionary object

Define the JS action object:

xref = doc.get_new_xref()
js = "the javascript text"
objsource = f"<</Type/Action/S/JavaScript/JS({js})>>"
doc.update_object(xref, objsource)

Update the catalog:

cat = doc.pdf_catalog()
doc.xref_set_key(cat, "OpenAction", f"{xref} 0 R")

Then save. Fingers crossed that everything works ... 😎

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deven740
Comment options

Answer selected by deven740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants