PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
SDK 使用前提及通用导入请参见数字签名概览。
| 操作 | API | 含义 |
|---|---|---|
| 签名内嵌时间戳 | CPDFDocument.writeSignature(..., tsaUrl) 或 PAdES T/LT/LTA 创建 | 容器内的 token 绑定签名值 |
| 独立文档时间戳 | CPDFTimestampService.addDocumentTimestamp() | 新 ETSI.RFC3161 域保护 PDF 修订版 |
| 数据或摘要 token | timestampData() / timestampDigest() | 返回 DER RFC 3161 token,不修改 PDF |
本地签署时间属性不是可信 TSA 时间戳。
追加文档时间戳
文档时间戳使用 TSA 身份,无需用户签名私钥,可追加在二阶段签名结果上。
Files.createDirectories(Paths.get("output"));
CPDFTimestampOptions tsa = new CPDFTimestampOptions()
.setTsaUrl("https://tsa.example.com/timestamp")
.setTransport(20, 0, "");
CPDFSignatureOptions field = new CPDFSignatureOptions()
.setFieldName("DocumentTime")
.setValidationOptions(new CPDFSignatureValidationOptions()
.setTrustedCertPath("certs/trusted-roots.pem"));
CPDFSignatureCreateResult result = CPDFTimestampService.addDocumentTimestamp(
"output/external-signed.pdf",
"output/timestamped.pdf",
tsa,
field);
System.out.println("Creation success: " + result.isSuccess());
System.out.println(result.getValidationResult());输出须为新路径且与输入不同。当前文档时间戳 signer 使用 SHA-256,选择其他摘要会被明确拒绝。该操作不收集 DSS/VRI,也不自动代表 PAdES-LTA。TSA 失败时不发布最终 PDF。
请求数据或摘要 token
支持 SHA-256/384/512。传输配置包括超时、重试、代理和最大响应大小;请求配置包括 policy OID、nonce 以及是否要求响应包含证书。
byte[] data = Files.readAllBytes(Paths.get("input.pdf"));
CPDFTimestampOptions options = new CPDFTimestampOptions()
.setTsaUrl("https://tsa.example.com/timestamp")
.setDigestAlgorithm(CPDFSignatureDigest.SHA256)
.setTransport(20, 0, "");
CPDFTimestampResult result = CPDFTimestampService.timestampData(data, options);
if (result.isSuccess()) {
Files.createDirectories(Paths.get("output"));
Files.write(Paths.get("output/timestamp-token.der"), result.getTokenDer());
System.out.println("TSA generation time: " + result.getGenerationTime());
} else {
System.out.println(result.getErrorCode() + ": " + result.getErrorMessage());
}已有 imprint 时,使用 timestampDigest() 传入与算法对应的原始摘要字节,不重复摘要。
TSA 请求成功不等于证书可信。PDF 时间戳应检查 imprint、密码学签名及 TSA 信任链。HTTPS 和证书信任使用 native OpenSSL 配置,不是 JVM trust store。
SignatureTimestampTest 演示内嵌时间戳、独立文档时间戳及两种 token 请求。