向 PDF 添加签名字段并进行签名

向 PDF 添加签名字段并进行签名
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{eforms}
\usepackage{aeb_pro}
%\begin{docassembly}
%\signInfo{cSigFieldName:"mySig",ohandler:security.PPKLiteHandler,cert:"D_P_Story.pfx",password:"dps017",oInfo:{location:"Niceville, FL",reason:"I am approving this document",contactInfo:"[email protected]",appearance:"My Signature"}};
%\signatureSign
%\end{docassembly}
\begin{document}
\sigField[\BC{0 0 0}]{mySig}{2in}{4\baselineskip}
\end{document}

将创建一个包含签名字段的 PDF 文件。取消注释四行注释代码时,pdflatex 编译将抛出错误:

[...]
[Loading MPS to PDF converter (version 2006.09.02).]
) (docassembly.djs
(C:\Users\xxx\AppData\Local\Programs\MiKTeX\tex/latex/acrotex\dljscc.def)
! Undefined control sequence.
\expVerb ->\signInfo
                     {cSigFieldName:"mySig",ohandler:security.PPKLiteHandler...
l.18 [email protected]",appearance:"My Signature"}};

?

我从eforms 手动的。需要指定用于签名的 .pfx 的文件名,app.getPath( {cCategory:"user"})/SecurityAcrobat 的 .pfx 文件的保存目录在哪里。我很确定这是C:\Users\xxx\AppData\Roaming\Adobe\Acrobat\DC\Security。但是,我认为这可能有已更改适用于 Acrobat,因为建议将签名现在存储在文件 reader_fss_signature_initials和中reader_fss_signature_initialsi

a) 我感觉该Undefined control sequence错误与某些不兼容性(在 Windows 10 上运行最新的 MiKTeX)有关,而不是与丢失的 .pfx 文件有关(当然,我D_P_Story.pfx手头没有软件包作者的文件)。

b) 是否有任何程序可以在编译时或首次打开 PDF 时自动对 LaTeX 生成的 PDF 进行签名?显然,.pfx 文件不再是文件系统可访问的(此处使用 Acrobat Pro DC 2021.x)。

答案1

首先,我确保已aeb_pro正确安装,请参阅手册第 2.7 章和。从install_jsfiles.pdf,我创建了所有文件夹,并将和复制到此位置。我从中获取了 .js 文件C:\Program Files\MiKTeX\doc\latex\aeb-procmd.exe%AppData%\Adobe\Acrobat\Privileged\DC\JavaScriptsaeb.jsaeb_pro.js这里

我联系了此软件包的作者 Story 博士,他给了我很大的帮助。首先,他推荐我阅读两篇(12) 的文章。docassembly环境可能包含必须扩展为 JS 的 LaTeX 代码。我认为eforms 手动的因为命令是\sigInfo{}而不是\signInfo{}。因此,代码

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{eforms}
\usepackage{aeb_pro}
\begin{docassembly}
\sigInfo{
    cSigFieldName:"mySig",
    ohandler:security.PPKLiteHandler,
    cert:"xxx.pfx", % insert name of .pfx located in %AppData%\Adobe\Acrobat\DC\Security
    password:"yyy", % insert the password for xxx.pfx
    oInfo:{
        location:"Niceville, FL",
        reason:"I am approving this document",
        contactInfo:"[email protected]",
        % appearance:"My Signature" % only uncomment and set this if you actually have an appearance defined
    }
};
\signatureSign
\end{docassembly}
\begin{document}
\sigField[\BC{0 0 0}]{mySig}{2in}{4\baselineskip}
\end{document}

将成功编译,并且(在 .pdf 文件旁边)还会生成 docassembly.djs 和 docassembly.fdf。使用 Acrobat 打开 PDF 时,JavaScript 代码将从 docassembly.fdf 导入。签名字段应自动签名。目前,仅%AppData%\Adobe\Acrobat\DC\Security支持位于 的 .pfx 文件。据我所知,目前不支持位于 Windows 证书存储中的证书。

答案2

如果您不是使用 Windows,那么aeb_pro它就无法满足您的需求(它需要安装 Acrobat Reader 并将其整合到工作流程中)。现在,poppler 支持签名,您可以pdfsig在整合签名字段后使用它来签署 PDF。例如,要签署第一个签名字段,请使用:

pdfsig -sign 1 -nick 'NAME OF SIGNATURE' in.pdf out.pdf

NAME OF SIGNATURENSS 数据库中 PKCS#12 证书的“友好名称”在哪里。您可以使用pdfsig -list-nicks列出当前安装的签名及其昵称。如果您没有安装任何证书,那么有很多关于如何生成(视窗Linux) 证书和将它们导入到 Firefox。请注意,这pdfsig只是应用签名,如果您想在“单击签名”字段的位置放置图像或文本,则需要单独执行此操作。

相关内容