百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
J

JS2PDFInjector

> 编程语言
开源

将 JS 文件注入到 PDF 文件中。

385 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

将 JS 文件注入到 PDF 文件中。

JS2PDFInjector

Use this tool to Inject a JavaScript file into a PDF file.

To do this you will need an existing PDF file, and a ".js" file which contains the commands you would like to run when the document is opened. I use this to create PDFs with some active code in there that I can email to customers, or download through their proxies, to check for the JavaScript being removed or blocked. When you open the produced PDF with the JavaScript injected in Adobe you should see your code execute. Mileage varys in other viewers and for certain Edge in Windows 10 does not execute.

JavaScript API available in PDF

The following URL contains the JavaScript API details:

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf

These are different from browser based JavaScript so reading that to achieve anything advanced is recommended.

Example JavaScript

Who doesn't love a simple alert message? I know I do. The following code is all you will need for your hello world alert message:

app.alert("Hello world!");

A little different from just "alert". Your alert method now lives attached to the "app" object. Nothing too crazy.

How to use

Follow the steps below to create your PDF:

  • Execute the jar file.
  • If no command line arguments are provided "usage" instructions will be provided
  • Then it will open a GUI prompt that asks you to point it at a PDF file.
  • Select the PDF file you would like to inject in to.
  • Another prompt will appear looking for the file containing your JavaScript.
  • Select that file.
  • This will create a new file in the same directory as the PDF with "js_injected_" prepended in the name.

To automate the process via the command line the following shows the new usage:

java -jar JS2PDFInjector.jar

This does no checking that the files you provide exist so don't run with scissors.

If you need to inject one JS file into multiple PDF files then you can do so with a for loop. For bash that is shown below:

for pdf in /path/to/pdfs/*.pdf
do;
java -jar JS2PDFInjector.jar $pdf /path/to/javascript.js
done;

I have not spent time on crafting the interface. But this should work.

Common Error

When running in headless mode if you see a FileNotFoundException like this:

…

It means you used relative paths to the files. Please supply the absolute path as command line arguments. So instead of this command:

java -jar JS2PDFInjector.jar dummy.pdf test.js

You should use absolute paths like this:

java -jar JS2PDFInjector.jar /tmp/dummy.pdf /tmp/test.js

Full paths for the win.

How to use JS2PDFInjector to Test your Email or Internet filtering

For more information please see the blog post by the author:

https://cornerpirate.com/2017/02/10/js2pdfinjector-javascript-for-your-pdf/

The blog post is no outdated and shows only the GUI usage path.

Dislaimer

For research purposes only, do not use this on any target which you do not have permission to do so.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Java

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言