You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于iTextSharp创建不可编辑且支持数字签名的PDF问题

PDF加密后无法添加数字签名,需实现只读且允许客户签名

我目前使用EncryptPdfData方法加密PDF数据,原本期望实现PDF只读且支持数字签名,但尝试签名时触发以下错误:

当前文档不允许创建新签名,原因:
PDF权限字典不允许在用户访问模式下修改或创建包括签名域在内的交互式表单字段!

我的需求是:生成一份不可编辑内容的PDF提供给客户,同时允许客户在线添加数字签名(签名操作不能修改原文档内容)。

当前使用的C#代码如下:

private byte[] EncryptPdfData(byte[] pdfData)
{
    // Create a memory stream to work with the PDF data
    using (MemoryStream ms = new MemoryStream())
    {
        // Create a PdfReader to read the existing PDF data
        using (PdfReader reader = new PdfReader(pdfData))
        {
            // Create a PdfStamper to modify the PDF
            using (PdfStamper stamper = new PdfStamper(reader, ms))
            {
                // Set encryption options
                stamper.SetEncryption(null, // User password (empty means no password)
                                      null, // Owner password (empty means no password)
                                      PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_MODIFY_ANNOTATIONS, // Permissions (allow printing and modify annotations)
                                      PdfWriter.ENCRYPTION_AES_128); // Encryption strength

                // Ensure the changes are applied
                stamper.Close();
            }
        }

        // Return the encrypted PDF data
        return ms.ToArray();
    }
}

内容的提问来源于stack exchange,提问作者serbian_warrior

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 09:07:06