Class PdfSigner
java.lang.Object
cloud.opencode.base.pdf.signature.PdfSigner
PDF Digital Signer
PDF 数字签名器
Signs PDF documents with digital signatures using PKCS#7.
使用 PKCS#7 对 PDF 文档进行数字签名。
Features | 主要功能:
- Digital signature with certificates - 使用证书进行数字签名
- Visible signature appearance - 可见的签名外观
- Timestamp support - 时间戳支持
- Multiple signature fields - 多签名字段
Usage Examples | 使用示例:
// Sign a PDF
PdfSigner.create()
.keyStore(Path.of("keystore.p12"), "password".toCharArray(), "PKCS12")
.alias("mycert")
.reason("Contract Approval")
.location("New York")
.sign(Path.of("document.pdf"), Path.of("signed.pdf"));
Security | 安全性:
- Thread-safe: No — not designed for concurrent use - 线程安全: 否 — 非并发设计
- Null-safe: Yes — parameters are validated - 空值安全: 是 — 参数已验证
- Sensitive data: Key store passwords are cloned defensively - 敏感数据: 密钥库密码进行了防御性克隆
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionSets the certificate alias to use.appearance(SignatureAppearance appearance) Sets signature appearance.Sets signature contact info.static PdfSignercreate()Creates a new signer.Sets signature field name.getAlias()floatintfloatgetWidth()floatgetX()floatgetY()keyPassword(char[] password) Sets private key password (if different from keystore).keyStore(InputStream keyStoreStream, char[] password, String type) Sets the key store from input stream.Sets the key store for signing.Sets signature location.Sets signature reason.rectangle(int pageNumber, float x, float y, float width, float height) Sets signature rectangle position.sign(PdfDocument document) Signs a PDF document object.Signs a PDF document.voidSigns and saves to file.Enables timestamp.Enables timestamp with authentication.
-
Method Details
-
keyStore
-
keyStore
Sets the key store from input stream. 从输入流设置密钥库。- Parameters:
keyStoreStream- key store stream | 密钥库流password- key store password | 密钥库密码type- key store type | 密钥库类型- Returns:
- this signer | 当前签名器
-
alias
-
keyPassword
Sets private key password (if different from keystore). 设置私钥密码(如果与密钥库不同)。- Parameters:
password- private key password | 私钥密码- Returns:
- this signer | 当前签名器
-
appearance
Sets signature appearance. 设置签名外观。- Parameters:
appearance- signature appearance | 签名外观- Returns:
- this signer | 当前签名器
-
reason
-
location
-
contact
-
fieldName
-
rectangle
Sets signature rectangle position. 设置签名矩形位置。- Parameters:
pageNumber- page number | 页码x- x coordinate | x 坐标y- y coordinate | y 坐标width- width | 宽度height- height | 高度- Returns:
- this signer | 当前签名器
-
timestamp
-
timestamp
-
sign
Signs a PDF document. 对 PDF 文档签名。- Parameters:
source- source PDF | 源 PDF- Returns:
- signed PDF document | 签名后的 PDF 文档
- Throws:
OpenPdfException- if signing fails | 签名失败时抛出异常
-
sign
Signs and saves to file. 签名并保存到文件。- Parameters:
source- source PDF | 源 PDFtarget- target file | 目标文件- Throws:
OpenPdfException- if signing fails | 签名失败时抛出异常
-
sign
Signs a PDF document object. 对 PDF 文档对象签名。- Parameters:
document- PDF document | PDF 文档- Returns:
- signed PDF document | 签名后的 PDF 文档
- Throws:
OpenPdfException- if signing fails | 签名失败时抛出异常
-
getKeyStorePath
-
getKeyStoreType
-
getAlias
-
getAppearance
-
getReason
-
getLocation
-
getContact
-
getFieldName
-
getPageNumber
public int getPageNumber() -
getX
public float getX() -
getY
public float getY() -
getWidth
public float getWidth() -
getHeight
public float getHeight() -
getTsaUrl
-
create
-