Digitally sign PDF files from your commandline
| Files | Last commit | Last update |
|---|---|---|
| 11 months ago | ||
| 7 months ago | ||
| 4 years ago | ||
| 3 years ago | ||
| 3 years ago | ||
| 7 months ago | ||
| 11 months ago |
Translated by AI, submit an issue feedback
open-pdf-sign
open-pdf-sign 命令行应用程序可让您轻松地从命令行对 PDF 文件进行签名。签名可以是不可见的(默认)或可见的(可自定义)。
功能
- PDF 中的可见 PDF 签名(支持多语言)
- 通过 CLI 调用或通过启动服务器调用
- 支持的签名类型:PAdES
- 支持的签名配置文件:
- BASELINE-B
- BASELINE-T
- BASELINE-LT
- BASELINE-LTA
快速开始
从 GitHub 发布页面 下载最新的 JAR 文件,或在终端中执行以下命令:
curl --location --output open-pdf-sign.jar \
https://github.com/open-pdf-sign/open-pdf-sign/releases/latest/download/open-pdf-sign.jar
此外,open-pdf-sign 也可在 nix 上获取,npm 上提供了一个包装器,同时还提供了适用于 nginx 的安装程序。
请确保已安装至少 11 版本的 Java。
运行
java -jar open-pdf-sign.jar \
--input input.pdf --output output.pdf \
--certificate certificate.crt --key keyfile.pem --passphrase key_passphrase \
--page -1 --locale de-AT
使用方法:
Options:
--add-page
add a blank page to the end of the document before signing
--baseline-lt
use PAdES profile with long-term validation material
--baseline-lta
use PAdES profile with long term availability and integrity of validation material
-b, --binary
binary output of PDF
Default: false
-c, --certificate
certificate (chain) to be used
--certification
Quality of signature certification (DocMDP) and allowed changes after
signing
Default: certified-minimal-changes-permitted
Possible Values: [not-certified, certified-no-change-permitted, certified-minimal-changes-permitted, certified-changes-permitted]
--config
use a configuration file
-h, --help
prints this page
--hint
text to be displayed in signature field
--host
run as server with the given hostname
--image
Image to be placed in signature block
--image-only
Only use the image as signature content
Default: false
-i, --input
input pdf file
-k, --key
signature key file or keystore
--label-hint
label for the 'hint' row
--label-signee
label for the 'signee' row
--label-timestamp
label for the 'timestamp' row
--left
X coordinate of the signature block in cm
Default: 1.0
-l, --locale
Locale, e.g. de-AT
--no-hint
don't display a hint row
-o, --output
output pdf file
--page
Page where the signature block should be placed. [-1] for last page
-p, --passphrase
passphrase for the signature key or keystore
--pdf-passphrase
Password required for reading a password-protected PDF input file
--port
run as server with the given port
--signature-contact
Contact information of the signer
--signature-location
The signer's location
--signature-reason
The signature creation reason
--timestamp
include signed timestamp
Default: false
--timezone
use specific timezone for time info, e.g. Europe/Vienna
--top
Y coordinate of the signature block in cm
Default: 1.0
--tsa
use specific time stamping authority (TSA) as source (if multiple given, will
be used in given order as fallback)
Default: []
--tsa-username
username for TSA server
--tsa-password
password for TSA server
--version
prints version of this program
--width
width of the signature block in cm
Default: 10.0
使用 Let's Encrypt 证书
您也可以使用现有的 Let's Encrypt 证书对 PDF 进行签名。
java -jar open-pdf-sign.jar --input input.pdf --output output.pdf \
--certificate /etc/letsencrypt/live/openpdfsign.org/fullchain.pem \
--key /etc/letsencrypt/live/openpdfsign.org/privkey.pem
使用长期验证信息签署文档(PAdES-LT)
签署文档时,通过整合所有验证签名所需的材料或材料引用,确保验证材料的长期可用性。为此,需要使用时间戳。
java -jar open-pdf-sign.jar --input input.pdf --output output.pdf \
--certificate /etc/letsencrypt/live/openpdfsign.org/fullchain.pem \
--key /etc/letsencrypt/live/openpdfsign.org/privkey.pem \
--timestamp --tsa http://timestamp.digicert.com
--baseline-lt
可见签名
如果指定了 page 参数,可见签名将被放置在指定页面上。
例如,运行
java -jar open-pdf-sign.jar --input input.pdf --output output.pdf \
--certificate certificate.crt \
--key key.pem \
--page -1 --image mylogo.png \
--hint "You can check the validity at https://www.signaturpruefung.gv.at"
会在 PDF 文档的最后一页(-1)上放置一个可见签名,其外观与下图相似。

服务器模式使用方法
您还可以将 open-pdf-sign 作为服务器应用程序运行,以便仅加载一次证书,并轻松将其集成到无法进行 CLI 调用的应用程序中。只需添加 port 或 host 参数,例如
java -jar open-pdf-sign.jar --input input.pdf --output output.pdf \
--certificate /etc/letsencrypt/live/openpdfsign.org/fullchain.pem \
--key /etc/letsencrypt/live/openpdfsign.org/privkey.pem
--port 8090 --host 127.0.0.1
然后,可以通过 指定的 POST 请求对 PDF 进行签名:
curl --location 'http://localhost:8090/' \
--header 'Content-Type: application/json' \
--data-raw '{"input":"/path/to/pdf.pdf"}'
使用配置文件
您无需通过 CLI 参数指定所有内容,也可以使用配置文件(例如 此文件):
java -jar open-pdf-sign.jar --config /path/to/config.yaml
这样,您还可以配置多个(虚拟)主机。
开发
要求
- Maven
- JDK 11
构建
mvn package
许可协议
本项目基于 Apache 2.0 许可协议 授权。
org/openpdfsign/dss 子文件夹 中包含的代码,是对 dss 项目 代码的扩展与修改,该部分代码基于 LGPL-2.1 许可协议 授权。
本项目获得了 netidee 的资金支持。