How can I put JavaScript code into a PDF document?

前端 未结 3 1896
迷失自我
迷失自我 2020-12-30 05:44

How do I insert JavaScript code into a PDF file?

I can code JavaScript, I just wish to know how to put it into a file to, for example, display the current date, use

相关标签:
3条回答
  • 2020-12-30 06:23

    JavaScript is typically tied to objects in a PDF document. For example, if you want the user to be able to print the PDF by clicking a Print button, follow the steps below:

    • Add a button to the form (done under advanced editing)
    • Right click on the button and go to properties
    • Click the actions tab
    • Under Select Action: choose Run a JavaScript
    • put print(); in the code window

    Here's a link to an old (Acrobat 7.0.5) Acrobat JavaScript Scripting Reference to get you started.

    Fresh Links 22/06/2020

    • Adobe Acrobat 7.0 JavaScript Scripting Reference
    • JavaScript for Acrobat API Reference
    0 讨论(0)
  • 2020-12-30 06:30

    You didn't stipulate a constraint for language, so you can use Python to achieve this. The library PyPDF2 has a class called addJS that works. Here is an example from the REPL:

    mypdf.addJS("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")

    and here is a link to the documentation. Note, that you need to have python3 installed (2.7 is going away at the end of 2019) and then run pip3 install PyPDF2 or similar to install the library and then load it via import PyPDF2. Hopefully that helps.

    0 讨论(0)
  • 2020-12-30 06:31

    There are many ways to do it if you search on Google about it.

    Here is an example of what i found to insert JavaScript code into a PDF Document (you can also generate, edit, ... by JavaScript code) :

    Example insert JavaScript in PDF

    0 讨论(0)
提交回复
热议问题