使用 iTextSharp 在 PDF Reader 中启用保存选项

Enable save option in PDF Reader using iTextSharp

我使用 iTextSharp 开发了一个可编辑的 PDF

我的密码是:

//Creating a document
        Document document = new Document(PageSize.A4, 50, 50, 25, 25);

        FileStream pdfFileStream = new FileStream("D:\new.pdf", FileMode.Create);

//Writing to PDF
        using (PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfFileStream))
        {
            //Opening the document for writing
            document.Open();
            PdfContentByte cb = pdfWriter.DirectContent;

            Paragraph para = new Paragraph("Name");
            document.Add(para);

            //Creating the text box starts here --->
            TextField _text = new TextField(pdfWriter, new Rectangle(100, 806, 170, 790), "Name");
            _text.BackgroundColor = BaseColor.LIGHT_GRAY;
            _text.Alignment = Element.ALIGN_CENTER;
            //_text.Options = TextField.MULTILINE;
            _text.Text = "";
            pdfWriter.AddAnnotation(_text.GetTextField());
            cb = pdfWriter.DirectContent;

            //Creating the text box ends here ---<

            //Creating the RadioButton group starts here ---->

            PdfFormField _radioGroup = PdfFormField.CreateRadioButton(pdfWriter, true);
            _radioGroup.FieldName = "Gender";

            string[] genders = { "Male", "Female" };

            RadioCheckField genderRadioCheckField;
            PdfFormField radioGField;

            for (int i = 0; i < genders.Length; i++)
            {
                genderRadioCheckField = new RadioCheckField(pdfWriter, new Rectangle(40, 806 - i * 40, 60, 788 - i * 40), null, genders[i]);

                genderRadioCheckField.BackgroundColor = BaseColor.LIGHT_GRAY;
                genderRadioCheckField.CheckType = RadioCheckField.TYPE_CIRCLE;

                radioGField = genderRadioCheckField.RadioField;
                ColumnText.ShowTextAligned(cb, Element.ALIGN_LEFT, new Phrase(genders[i], new Font(Font.FontFamily.HELVETICA, 12)), 70, 790 - i * 40, 0);
                _radioGroup.AddKid(radioGField);

            }

            pdfWriter.AddAnnotation(_radioGroup);
            cb = pdfWriter.DirectContent;
            //Creating the RadioButton group ends here ----<



            //Closing the document for writing
            document.Close();

            Console.WriteLine("Completed");
            Console.ReadLine();

        }

现在,代码生成带有文本字段和单选按钮的可编辑 PDF。

问题是:

我使用 Adobe Reader 打开生成的 PDF 文件,并在 Text Field 中输入了一些文本, 试图保存它

我在 File 菜单下找不到任何 save 选项,但我也尝试使用 Save As- -> PDF,显示消息为:

"This document does not allow you to save any changes you have made to it unless you are using Adobe Acrobat X standard,Adobe Acrobat X pro,Adobe Acrobat X knowledge worker suite. You will be only saving the copy of the document. Do you want to continue?"

如何在 Adob​​e PDF 中启用保存选项 Reader?。我的 C# 代码有问题吗?

您想Reader启用您的 PDF。 Reader 启用涉及使用 Adob​​e 拥有的私钥添加数字签名。当 Adob​​e Reader 检测到该签名并且签名有效时,Adobe Reader 解锁仅在 Adob​​e Acrobat 中可用的功能(取决于您在签署文档时定义的使用权限)。

你的C#没有问题。主要问题是您要求的功能需要访问 Adobe 拥有的私钥。 没有第三方产品被授予访问该密钥的权限。您只能 reader 使用 Adob​​e 软件启用 PDF 文档。 iText、iTextSharp 或 Adob​​e 产品以外的任何其他软件 Reader 启用文档都是非法的。

总结:您要求的功能只有在使用 Adob​​e 软件时才可用。不允许第三方供应商提供该功能(除非他们拥有 Adob​​e 的许可)。

解法:

我使用 Adobe Reader X 如果我们使用 iTextSharp.dll,它不支持保存选项。最后,我下载了最新版本的 Adob​​e Reader DC,它运行良好。现在,我可以编辑和保存我的文档了。感谢所有其他回复。

尝试使用打印到磁盘的 BullZIP PDF 打印机