Skip to content
DemoAPI 参考文档FAQ

PDF 生成模板编辑器

开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。

查看 GitHub
React Native Guides Timestamps and ltv

时间戳与长期验证 ​

签名时间戳用于证明签名在某一时间已存在。长期验证(LTV)将证书及吊销信息等材料写入 PDF,供后续验证使用。两者与签名有效性、证书信任分别判断。

添加签名时间戳 ​

在 writeSignature() 的配置中设置 timestampServerUrl,其余步骤与创建数字签名相同。

ts
import type { CPDFSignatureConfig }
  from '@compdfkit_pdf_sdk/react_native';

function timestampConfig(certificatePath: string, password: string): CPDFSignatureConfig {
  return { certificatePath, password,
    timestampServerUrl: 'https://tsa.example.com/timestamp' };
}

示例地址为占位符,请替换为可访问的 RFC 3161 HTTP(S) 时间戳服务。网络、服务或验证失败会使签署调用失败,不会自动退回不带时间戳的签署。

验证结果中的 timestampSource 对应 CPDFSignatureTimestampSource:NONE 为无时间来源,LOCAL_CLOCK 为本地时钟,EMBEDDED 为内嵌签名时间戳,DOCUMENT 为文档时间戳。还应检查 timestampTrusted 和 embeddedTimestampValid。

检查长期验证材料 ​

ts
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';

async function inspectLtv(reader: CPDFReaderView) {
  if (!await reader.save()) throw new Error('保存文档失败');
  const readiness = await reader._pdfDocument.getLtvReadiness();
  return readiness;
}

getLtvReadiness() 检查已保存文件的文档级材料。success 表示检查是否成功,ltvReady 表示材料是否满足就绪条件;hasDss、hasVri、hasCertificates、hasRevocation 描述材料类型。可通过 missingMaterials、材料计数、errors 和 warnings 了解缺失项及诊断信息。

材料就绪不等同于签名有效或证书受信任,仍需调用 verifyDigitalSignature()。

添加长期验证材料 ​

先打开已保存的签名 PDF。trustedCertificatePath 为本地 PEM 信任根证书;输出目录须存在,输出文件须与源文件不同。

ts
import { CPDFReaderView } from '@compdfkit_pdf_sdk/react_native';

async function addLtv(reader: CPDFReaderView,
  trustedCertificatePath: string, outputPath: string) {
  if (!await reader.save()) throw new Error('保存文档失败');
  const result = await reader._pdfDocument.addSignatureLtv(outputPath, {
    trustedCertificatePath,
  });
  if (!result.success || !result.finalPath) {
    throw new Error(JSON.stringify(result.errors));
  }
  if (!await reader._pdfDocument.open(result.finalPath)) {
    throw new Error('打开长期验证文件失败');
  }
  return result;
}

可选 ocspUrls 和 crlUrls 指定证书状态与吊销列表来源。收集材料可能需要网络访问。结果提供 success、ltvPath、ltaPath、finalPath、errors 和 warnings;即使 Promise 成功返回,也应检查 success 及诊断信息。

追加文档时间戳

在同一选项对象中增加 appendDocumentTimestamp: true、timestampServerUrl 和 timestampOutputPath,生成带文档时间戳的 LTA 副本。源文件、LTV 输出和时间戳输出必须使用不同路径。接口不会自动切换当前阅读器,应确认成功后打开 finalPath,重新检查材料及签名。参数或桥接错误也可能直接拒绝 Promise。