我使用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 .
Problem is:
我使用 Adobe Reader 打开生成的PDF文件,并在 Text Field
和 Tried to save it 中输入了一些文本 .
我在 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?"
如何在Adobe PDF Reader中启用保存选项?我的C#代码有问题吗?
3 回答
您希望Reader启用您的PDF . 阅读器启用涉及使用Adobe拥有的私钥添加数字签名 . 当Adobe Reader检测到该签名以及签名有效时,Adobe Reader将解锁仅在Adobe Acrobat中可用的功能(取决于您在签署文档时定义的使用权限) .
你的C#没问题 . 主要问题是您要求的功能需要访问 a private key owned by Adobe. 没有第三方产品被授予对该密钥的访问权限 . 您只能使用Adobe软件阅读器启用PDF文档 . 对于iText,iTextSharp或除Adobe产品以外的任何其他软件,Reader启用文档都是非法的 .
Summarized: 您要求的功能仅在使用Adobe软件时可用 . 不允许第三方供应商提供该功能(除非他们拥有Adobe的许可) .
Solution:
如果我们使用
iTextSharp.dll
,我使用了不支持保存选项的Adobe Reader X.最后,我下载了最新版本的Adobe Reader DC,它运行正常 . 现在,我可以编辑和保存我的文档 . 感谢所有其他回复 .尝试使用BullZIP PDF打印机打印到磁盘