问题描述
I am using This example for the latest Itext7 to fill in a document and I am getting this error: iText.Kernel.Crypto.BadPasswordException: PdfReader is not opened with owner passwordSo I looked around the net I found that some people found solution to this error using PdfReader.unethicalreading = true;
but when I try to use this same code it says there is no definition in PDFReader named unethicalreading
这是我拥有的代码:
string src = @"C:\test1.pdf";
string dest = @"C:\Test2.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetFormFields();
PdfFormField toSet;
fields.TryGetValue("Name", out toSet);
toSet.SetValue("Some text");
推荐答案
您需要像这样更改代码:
You need to change your code like this:
string src = @"C:\test1.pdf";
string dest = @"C:\Test2.pdf";
PdfReader reader = new PdfReader(src);
reader.setUnethicalReading(true);
PdfDocument pdfDoc = new PdfDocument(reader, new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
IDictionary<String, PdfFormField> fields = form.GetFormFields();
PdfFormField toSet;
fields.TryGetValue("Name", out toSet);
toSet.SetValue("Some text");
这将使您违反文档原始作者所定义的权限.这也证明了设置这种权限已经过时了,因为自从PDF成为ISO标准以来,删除这些权限不再受罚.
This will allow you to go against the permissions that were defined by the original author of the document. This also proves that setting such permissions has become obsolete, because since PDF became an ISO standard, there is no longer a penalty for removing those permissions.
这篇关于itext 7-使用所有者密码未打开PdfReader错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!