itext 7-使用所有者密码未打开PdfReader错误 [英] Itext 7 - PdfReader is not opened with owner password Error

查看:1174
本文介绍了itext 7-使用所有者密码未打开PdfReader错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此示例为最新的Itext7填写文档,我收到此错误:iText.Kernel.Crypto.BadPasswordException:PdfReader未使用所有者密码打开 因此,我环顾四周,发现有些人使用PdfReader.unethicalreading = true;找到了解决此错误的方法,但是当我尝试使用相同的代码时,它说PDFReader中没有名为unethicalreading

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 password So 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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆