[英]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
输入了一些文本,并尝试进行保存 。
我在“ 文件”菜单下找不到任何保存选项,但我也尝试使用“ 另存为”->“ PDF” ,它显示消息为:
“除非使用Adobe Acrobat X标准,Adobe Acrobat X pro,Adobe Acrobat X知识工作者套件,否则本文档不允许您保存对其所做的任何更改。您将仅保存该文档的副本。想继续吗?”
如何在Adobe PDF Reader中启用保存选项? 我的C#代码有什么问题吗?
您要阅读器启用 PDF。 启用阅读器涉及使用Adobe拥有的私钥添加数字签名。 当Adobe Reader检测到该签名并且该签名有效时,Adobe Reader将解锁本来只能在Adobe Acrobat中使用的功能(取决于您在签署文档时定义的使用权限)。
您的C#没有问题。 主要问题是您正在寻求需要访问Adobe拥有的私钥的功能。 没有第三方产品被授予对该密钥的访问权限。 您只能使用Adobe软件通过阅读器启用PDF文档。 对于iText,iTextSharp或Adobe产品以外的任何其他软件,使用Reader启用文档都是非法的。
总结:您要求的功能仅在使用Adobe软件时可用。 不允许任何第三方供应商提供该功能(除非他们具有Adobe的许可)。
解:
如果使用iTextSharp.dll
我使用的Adobe Reader X不支持保存选项。 最后,我下载了最新版本的Adobe Reader DC,它运行正常。 现在,我可以编辑和保存我的文档了。 感谢所有其他答复。
尝试使用可打印到磁盘的BullZIP PDF打印机
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.